Use Images to represent Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
soundbwoy
Forum Newbie
Posts: 21
Joined: Sat Jun 07, 2003 5:22 pm
Location: Orlando, FL

Use Images to represent Date

Post by soundbwoy »

How can I display images for Weekday, Month, Day, Year.

I was planning on either putting the paths to these images in a database or an array. and then somehow saving the date elements I need into thier own variables and somehow using that value to determine which image I will show. So for example:

If today is Saturday June 7th, 2003 I would like to display an HTML table with 4 colums each with an image of the propper date element. This date would equal the following images:

images/Weekday_saturday.gif
images/month_june.gif
images/day_07.gif
images/year_2003.gif

I have the images already in the images folder of my site. Now I just need to figure out how Im going to do all of this. It really can't be that hard could it?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Apologies I put a $ in front of time(). Correct version is:

Code: Select all

<?php
echo '<img src="images/Weekday_' . date('l', $timestamp) . '.gif">';
echo '<img src="images/month_' . date('F', $timestamp) . '.gif">';
?>
Rgr leave timestamp out to default to "now".
Last edited by McGruff on Thu Aug 11, 2005 6:46 am, edited 3 times in total.
User avatar
soundbwoy
Forum Newbie
Posts: 21
Joined: Sat Jun 07, 2003 5:22 pm
Location: Orlando, FL

Post by soundbwoy »

It can't be this easy. Im trying this for all elements, let me get back to you, Thanks.

Where Do I get the $Time function from?

Fatal error: Call to undefined function: ()
Last edited by soundbwoy on Sun Jun 08, 2003 2:13 am, edited 1 time in total.
User avatar
soundbwoy
Forum Newbie
Posts: 21
Joined: Sat Jun 07, 2003 5:22 pm
Location: Orlando, FL

Post by soundbwoy »

Code: Select all

<?php 

// use date() fn to get $variable element of img src: 

echo '<img src="images/Weekday_' . date('l') . '.gif">';
echo '<img src="images/month_' . date('F') . '.gif">';
echo '<img src="images/day_' . date('d') . '.gif">';
echo '<img src="images/year_' . date('y') . '.gif">';

// etc 

?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Ooops I edited last post instead of posting new message. See above.

Been working too hard I think 8O
User avatar
soundbwoy
Forum Newbie
Posts: 21
Joined: Sat Jun 07, 2003 5:22 pm
Location: Orlando, FL

Post by soundbwoy »

http://sdginteractive.com/sdghost/date.php

Works without the timestamp!

Here is the code I have working now in PHP, ASP & JavaScript:

PHP Example:

Code: Select all

<?PHP
echo '<img src="images/date/weekday_' . date('l') . '.gif">'; 
echo '<img src="images/date/month_' . date('F') . '.gif">'; 
echo '<img src="images/date/day_' . date('d') . '.gif">'; 
echo '<img src="images/date/year_' . date('y') . '.gif">';
?>
ASP Example:

Code: Select all

&lt;%
strDate = Day(Date)
Response.write "&lt;img src=""images/date/Weekday_" &amp;  WeekDayName(WeekDay(Now())) &amp; ".gif""&gt;"
Response.write "&lt;img src=""images/date/month_" &amp;  MonthName(Month(Now())) &amp; ".gif""&gt;"
Response.write "&lt;img src=""images/date/day_" &amp;  day(Date) &amp; ".gif""&gt;"
Response.write "&lt;img src=""images/date/year_" &amp; year(Date) &amp; ".gif""&gt;"
%&gt;
JavaScript Examle:

Code: Select all

&lt;script language="JavaScript" type="text/JavaScript"&gt;
&lt;!--
daysofweek   = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
monthsofyear = new Array('January','February','March','April','May','June','July','August'_
,'September','October','November','December');

d=new Date();
weekDayName = d.getUTCDay();
theMonth = d.getMonth();

document.write ("&lt;img src="images/date/wd_"+daysofweek&#1111;weekDayName]+".gif"&gt;");
document.write ("&lt;img src="images/date/"+monthsofyear&#1111;theMonth]+".gif"&gt;");
document.write ("&lt;img src="images/date/"+d.getUTCDate()+".gif"&gt;");
document.write ("&lt;img src="images/date/yr_"+d.getYear()+".gif"&gt;");
//--&gt;
&lt;/script&gt;
You can see how much easier it is in PHP than ASP or Javascript. In ASP you will have to escape the Quotes around the url in the IMG Tag and also if you decide to set extra parameters like Width, height or alt. So if you have a Quote inside ASP string you must use 2 quotes instead of one. In JavaScript I must create an array of months & weekdays first, because I couldn't figure out how to get back "Saturday" or "January" from the date function. Also you will have to escape your Quotes in Javascript also with a backslash before each quote.
Last edited by soundbwoy on Mon Jun 09, 2003 4:15 pm, edited 2 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

I've moved this to PHP - Normal as the Advanced forum is not really for questions like this.

Mac
User avatar
soundbwoy
Forum Newbie
Posts: 21
Joined: Sat Jun 07, 2003 5:22 pm
Location: Orlando, FL

Post by soundbwoy »

Thats cool, I think I deleted my last post? If nayone knows an easier way to do this in JavaScript let me know.
User avatar
soundbwoy
Forum Newbie
Posts: 21
Joined: Sat Jun 07, 2003 5:22 pm
Location: Orlando, FL

Post by soundbwoy »

Just found out how to do it in Javascript a bit easier, will post soon.
Post Reply