Forum Moderators: open

Message Too Old, No Replies

How do you put only Day and Date ona page

Day and Date

         

donnwar

10:14 pm on Dec 11, 2003 (gmt 0)

10+ Year Member



I was trying to get day and date (without time)on my page, can somebody help please. Thanks!

jatar_k

10:19 pm on Dec 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what language are you using?

donnwar

11:12 pm on Dec 11, 2003 (gmt 0)

10+ Year Member



I use html for pages but I believe the clock could be in JS?

jatar_k

11:31 pm on Dec 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try a search on google for

display date with javascript

there are a ton of them, though the couple I tested kept showing the year as 103, not sure why that is.

DrDoc

11:43 pm on Dec 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The year is supposed to be shown as 103 :)
103 years since 1900...

There are a few date functions that would be good to know:
getDate() = Date of the month (1-31)
getMonth() = Month (0-11)
getYear() = Years since 1900 (which means that you should add 1900 to the value)
getFullYear() = The actual year (may not work in really old browsers)
getDay() = Day of the week (0-6)

There are lots more... for hours, minutes, seconds, time zones, etc.

<script type="text/javascript">
months = new Array("January", "February", "March", "April" ,"May", "June", "July" ,"August", "September", "October", "November", "December");
now = new Date();
date = now.getDate();
month = months[now.getMonth()];
year = now.getFullYear();
document.write(month + " " + date + ", " + year);
</script>

This would output "December 11, 2003"

jatar_k

4:58 pm on Dec 12, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, I had no idea about that, thanks Doc.

donnwar

10:42 pm on Dec 13, 2003 (gmt 0)

10+ Year Member



Thanks Doc, I tried to play with it to include the day of the week but nothing showed you. Can you tell me how I could modify it to show as: Saturday, December 13 2004
Thanks

bruhaha

5:12 pm on Dec 15, 2003 (gmt 0)

10+ Year Member



Can you tell me how I could modify it to show as: Saturday, December 13 2004

First, I'll assume "2004" was a typo. Then:

1) add the following variable declarations:

days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

day =days[now.getDay()];

2) then add "day" to the document.write command:

document.write(day + " " + month + " " + date + ", " + year);

(Not sure if you want the comma where you displayed it above, but if so just exchange the first " " and the ",")

Incidentally, if you prefer (to shorten your code just a bit), you may omit the set of variable declarations for "day" "date" "month" and "year" and instead expand the document.write command as follows:

document.write(days[now.getDay()] + " " + months[now.getMonth()] + " " + now.getDate() + ", " + now.getFullYear());

donnwar

12:53 am on Dec 16, 2003 (gmt 0)

10+ Year Member



Thank You indeed