Hi,
I was wondering how websites have the date at the top of their pages, i.e.
Wednesday 18th April 2001
Thanks
Kam
| SitePoint Sponsor |
Hi,
I was wondering how websites have the date at the top of their pages, i.e.
Wednesday 18th April 2001
Thanks
Kam
One way...between <head></head> add:
Place this within your page where you would like it:Code:<SCRIPT LANGUAGE="JavaScript"> <!-- function MakeArray(n) { this.length = n return this } monthNames = new MakeArray(12) monthNames[1] = "January" monthNames[2] = "February" monthNames[3] = "March" monthNames[4] = "April" monthNames[5] = "May" monthNames[6] = "June" monthNames[7] = "July" monthNames[8] = "August" monthNames[9] = "September" monthNames[10] = "October" monthNames[11] = "November" monthNames[12] = "December" dayNames = new MakeArray(7) dayNames[1] = "Sunday" dayNames[2] = "Monday" dayNames[3] = "Tuesday" dayNames[4] = "Wednesday" dayNames[5] = "Thursday" dayNames[6] = "Friday" dayNames[7] = "Saturday" function customDateString() { currentDate = new Date() var theDay = dayNames[currentDate.getDay() + 1] var theMonth = monthNames[currentDate.getMonth() + 1] msie4 = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 )); if (msie4) { var theYear = currentDate.getYear() } else { var theYear = currentDate.getYear() +1900 } return theDay + ", " + theMonth + " " + currentDate.getDate() + ", " + theYear } //--> </SCRIPT>
Code:<SCRIPT LANGUAGE="JavaScript"> document.write(customDateString()) </SCRIPT>
I do believe it's a javascript. Here are some from JavaScript Source:
http://javascript.internet.com/clocks/index.html


Heh, I was almost finished writing an answer, and the power went out. Thankful only for a minute or so.
Anyway, JavaScript works best if you're on a server that doesn't support anything server side, like a free server. You can also use php, if your server supports it...
This would give you something like "Tuesday, April 17th, 2001"PHP Code:<?PHP
print date ("l, F jS, Y");
?>
You can also use SSI (again, only if your server supports it), but you have less control over the format of the output.
The trouble these two methods is they use the server's time, rather than the client's time. This can be overcome in PHP, if you know the client's time zone, but it's not great. JavaScript is probably the best bet. Just remember, not everyone has it turned on, though.Code:<!--#ECHO VAR="DATE_LOCAL" -->
Ed Rands
Hi,
Thanks very much for all the replies!
I've gone with the JavaScript - which works fine! - thx
Kam
Of course, the javascript solution will give the system date of the client machine which may be different to that of the server depending on where in the world the client is located.



and how to change the fonts, color, ????? (javascript one)
Brian





Brian - just add tags setting the font and colour around the script tag like this:Code:<font face="Verdana, Arial, Helvetica, sans-serif" size=2 color="#000000"><SCRIPT LANGUAGE="JavaScript"> document.write(customDateString()) </SCRIPT></font>
Thx Skunk plus that post on php/mysql was great!
Kam
Bookmarks