This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » Ajax & JavaScript » Insert Date into webpage
Reply

Insert Date into webpage

Paul Mowery
Member



Since: 23 Mar 2006
Posts: 1
Posted 23 Mar 2006 00:08:40

I found some code which is supposed to allow me to keep the date on my webpage and automatically update it when the page loads. I have tried going into code mode and pasting the code but it just comes out blank once it is published.

Here is the code I was using.

<script language="javascript">

function dodate() {
var dateis = new date;
var dayofweek = dateis.getDay();
var dayofmonth = dateis.getdate();
var x = new Array("Sunday,", "Monday,", "Tuesday,", "Wednesday,","Thursday,", "Friday,", "Saturday,";
var interrim;

if (dayofmonth == 1 ¦¦ dayofmonth == 21 ¦¦ dayofmonth == 31) {
interrim = "st";
}
else {
if (dayofmonth == 2 ¦¦ dayofmonth == 22) {
interrim = "nd";
}
else {
if (dayofmonth == 3 ¦¦ dayofmonth == 23) {
interrim = "rd";
}
else {
interrim = "th";
}
}
}

interrim = x[dayofweek] + " " + dayofmonth + interrim;
x = new Array("of January", "of February", "of March", "of April", "of May", "of June", "of July", "of August", "of September", "of October", "of November", "of December";
interrim = interrim + " " + x[dateis.getMonth()] +", ";
x = dateis.getYear();
if (x < 1999) { x += 1900; } return interrim + x;
}

window.document.write(dodate());

</script>

Thank you for any help you can provide.

I found some code which is supposed to allow me to keep the date on my webpage and automatically update it when the page loads. I have tried going into code mode and pasting the code but it just comes out blank once it is published.

Here is the code I was using.

<script language="javascript">

function dodate() {
var dateis = new date;
var dayofweek = dateis.getDay();
var dayofmonth = dateis.getdate();
var x = new Array("Sunday,", "Monday,", "Tuesday,", "Wednesday,","Thursday,", "Friday,", "Saturday,";
var interrim;

if (dayofmonth == 1 ¦¦ dayofmonth == 21 ¦¦ dayofmonth == 31) {
interrim = "st";
}
else {
if (dayofmonth == 2 ¦¦ dayofmonth == 22) {
interrim = "nd";
}
else {
if (dayofmonth == 3 ¦¦ dayofmonth == 23) {
interrim = "rd";
}
else {
interrim = "th";
}
}
}

interrim = x[dayofweek] + " " + dayofmonth + interrim;
x = new Array("of January", "of February", "of March", "of April", "of May", "of June", "of July", "of August", "of September", "of October", "of November", "of December";
interrim = interrim + " " + x[dateis.getMonth()] +", ";
x = dateis.getYear();
if (x < 1999) { x += 1900; } return interrim + x;
}

window.document.write(dodate());

</script>

Thank you for any help you can provide.
Peter Pritchard
Member



Since: 30 Jun 2001
Posts: 10
Replied 09 Oct 2009 00:33:51
If your page has .php ext, just use<?php echo date("l F d, Y";?>

Peter
Patrick Julicher
Official Representative



Since: 04 Feb 2002
Posts: 1,208
Replied 10 Oct 2009 16:15:53
Hi Peter/Paul,

There are numerous options to update todays date on a page. Google is your friend to finding various examples.

Kind regards, Patrick

Reply to this topic

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency