Forum Moderators: open

Message Too Old, No Replies

Automatically Update

         

kitster79

6:17 pm on Nov 5, 2008 (gmt 0)

10+ Year Member



Hi,

I'm not even sure if this request is resolvable with Javascript, but I am trying to have a piece of text within my HTML page automatically change its date when the file has been modified. Here is the URL to the page - you will see the bit of text towards the bottom "Last Updated..."

<snip>

Could some one please help me or point me in the right direction to achieve this?

Thanks

Kit

[edited by: eelixduppy at 5:21 am (utc) on Nov. 6, 2008]
[edit reason] no URLs, please [/edit]

astupidname

10:28 am on Nov 8, 2008 (gmt 0)

10+ Year Member



What you want for this is not javascript, but php would be the tool to use here. Your pages that use the following code will need to be named with a .php extension (not .html). Plug the following php code block in anywheres in the body of the document and it will display the "last modified" date and time of the current page (no need to supply it with the name of the page, it figures that out on it's own):

<?php
$currFiles = get_included_files();
$thisPage = $currFiles[0];
$file = fopen($thisPage,"r");
$filestats = fstat($file);
echo "This page last modified on: ".(date("F d Y g:i:sa",$filestats[9]));
fclose($file);
?>

Put that on a .php page and upload to php enabled server and you are good to go.

If you want to change the date and time formatting, see w3schools php date() function reference here [w3schools.com]
You can also look up the fopen() and fstat() functions at w3schools Complete PHP Filesystem Reference [w3schools.com]

(The fstat() function returns a unix timestamp, which we then convert to a formatted date in the code above)

If you would just want the date (of the last modification) to show and not the time (of the last modification) just remove the part that reads g:i:sa as that part displays the hour, minute, second, am & pm

astupidname

10:38 am on Nov 8, 2008 (gmt 0)

10+ Year Member



The fstat() function returns a unix timestamp

Oops, I am spreading inaccurate info there, sorry. The fstat() function actually returns an array of info items about the file, we later access item [9] in the array which is the last modified date as a unix timestamp format.