On my site I use the following code to tell users when I last updated my website:

Last updated: ', new Date(document.lastModified).toLocaleString(), '

This shows users something like this:

Last updated: 22 April 2006 12:53:12

Would it be possible to remove the time, so it just says:

Last updated: 22 April 2006

Thanks
Martin

OOps - Sorry I missed part of my code out (thought it didn't make sense!)

Here is the real code I currently use:

<script type="text/javascript">
document.write ('Last updated: ', new Date(document.lastModified).toLocaleString())
</script>

But I would like to remove he time from it (as I said above)

Thanks Again
Martin

You would use the various methods and properties of the Date() object to return just the portions you need:

http://www.w3schools.com/jsref/jsref_obj_date.asp

Or, you can use JavaScript's String() ojbect or RegEx to modify the string you display.

So would I do something like this?

<script type="text/javascript">
document.write ('Last updated: ', getDate(document.lastModified).toLocaleString(), 
getMonth(document.lastModified).toLocaleString(), 
getFullYear(document.lastModified).toLocaleString())
</script>

Hope that's right - I've not tested it though, so it's probably completely wrong!

Thanks
Martin

OK - that doesn't work because

'getDate' is undefined

Help?

Martin

Try this:

DLM=new Date(document.lastModified);
DLM_Y=DLM.getYear();
DLM_M=DLM.getMonth(); // Jan-Dec = 0-11
DLM_D=DLM.getDate();
if (DLM_Y < 70)   { DLM_Y=DLM_Y*1+2000; }
if (DLM_Y < 1000) { DLM_Y=DLM_Y*1+1900; }
DLM_M=DLM_M*1+1; // Jan-Dec = 1-12
if (DLM_M*1 < 10) { DLM_M='0'+DLM_M; } // leading zero
if (DLM_D*1 < 10) { DLM_D='0'+DLM_D; }
Out=DLM_M+'-'+DLM_D+'-'+DLM_Y;
document.write(Out);

That gives me something like:

04-24-2006

But I would still prefer it without the dashes and in english order (dd-mm-yyyy) instead of American order (mm-dd-yyyy).
That's simple enough to change:

DLM=new Date(document.lastModified);
DLM_Y=DLM.getYear();
DLM_M=DLM.getMonth(); // Jan-Dec = 0-11
DLM_D=DLM.getDate();
if (DLM_Y < 70) { DLM_Y=DLM_Y*1+2000; }
if (DLM_Y < 1000) { DLM_Y=DLM_Y*1+1900; }
DLM_M=DLM_M*1+1; // Jan-Dec = 1-12
if (DLM_M*1 < 10) { DLM_M='0'+DLM_M; } // leading zero
if (DLM_D*1 < 10) { DLM_D='0'+DLM_D; }
Out=DLM_D+' '+DLM_M+' '+DLM_Y;
document.write(Out);

But I would also like the month to be in text format:

24 April 2006

Can anyone canvert 1 into January, 2 to February etc.?

Martin

All of the information you need is in the link I provided above. With all due respect, I encourage you to do some of this work yourself. That's why I pointed you to the reference, rather than writing the code for you.

If you click that link, you'll see a complete list of every date-related Javascript method. Clicking "getMonth()" shows you detailed documenation about that method, including sample code for converting the month-number to a month name.

OK - sorry, I just assumed that it only explained what was said in the phrase by the link

Returns the month from a Date object (from 0-11)

Really Sorry ;)

Martin

I'm not mad, so no apology necessary. I just know from experience that you learn better by figuring things out yourself. This forum is a great resource for pointers in the right direction, so there was nothing wrong with starting the thread and asking some questions. You have to follow-up on the answers, though!

I hope your project turns out well.

Alright, thanks:cheesy: !

I'm working at it...

Martin

It's OK, I'm not putting the day on it.

Thanks anyway.:cheesy:

Martin

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.