PDA

View Full Version : improving this variable.


bazz
07-30-2004, 01:27 PM
HI,

I have this variable in a Javascript and I want to change it to collect the date from the server so that whenevber a user calls the script, the time is continually accurate. Since the language is client side, maybe the server time is not accessible but then I would have to use the computer time of the user.

The line of code is:

var todaysDate = "2003/04/24";

I am fed up having to change it every day :rolleyes:

Any tips welcome

Bazz

jamescover
07-30-2004, 02:33 PM
<script>
<!--

var todaysDate = new Date();
document.writeln(todaysDate);

//-->
</script>



-james

bazz
07-30-2004, 02:48 PM
That's great James.

Would I be correct that this will take the date from the users PC rather than from the server?

Bazz

jamescover
07-30-2004, 03:07 PM
Would I be correct that this will take the date from the users PC rather than from the server?


you would be correct, sir...



-james

Basscyst
07-30-2004, 04:13 PM
Hello -

If you want short date format:


funtion getTheDate()
{
var dt=new Date();
var m=dt.getMonth()+1;
var d=dt.getDate();
var y=dt.getYear();
var dt=m+'/'+d+'/'+y;
return dt;
}


Basscyst