Click to See Complete Forum and Search --> : "Latest update script" problemo


Fenster
09-03-2003, 05:33 PM
Ive been trying to create a script that shows the last time the page was updated, so far I managed, but I also tried to get the latest update date to be replaced by a text instead of numbers in a certain case: If the the page was updated the same day that its viewed the "last updated" would say Today instead of 03/04/2003 (or whatever) so it should compare the "last update" with the time, date on the local machine.
Is there some way of doing this? I been tring to fix it but Im just goin´ round in circles and its been ages since last programmed javascripts, theres probly some really easy solution to this but my brain has totally locked up so I would really need some advice and help with this.

Well heres the script as far as I managed:

<SCRIPT LANGUAGE="JavaScript">
<!-- Start
var mydate=new Date()
var dd = "<b>Last Update</B> " + document.lastModified;
var z = dd.length-8;
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
var localTime = "<b>Last Update</B> " + day, month, daym;

if (dd == localTime)
{
dd = document.write("<b>Today</b>");
}

document.writeln("");
document.write(dd.substring(z, 0));
document.writeln("");
// Slutt -->
</SCRIPT>



Id be really grateful for any help.
Thanks a bunch in advance.

Charles
09-03-2003, 05:48 PM
<script type="text/javascript">
<!--
Date.ONE_SECOND = 1000;
Date.ONE_MINUTE = Date.ONE_SECOND * 60;
Date.ONE_HOUR = Date.ONE_MINUTE * 60;
Date.ONE_DAY = Date.ONE_HOUR * 24;

modified = new Date(document.lastModified);
now = new Date();
document.write('<p>last modified: ', Math.floor(modified / Date.ONE_DAY) == Math.floor(now / Date.ONE_DAY) ? 'today' : modified.toDateString(), '</p>');
// -->
</script>

Fenster
09-03-2003, 07:30 PM
its all so clear now ;)

thanks a bunch! you the man.