PDQ Library:  Display File Date

Display Date of Last Update on a Web Page

It's often helpful for people using your Web site to know when a page was last updated. You usually want to add this information to the bottom of web pages. Pages that are time sensitive (event lists) may need this date at the top. Once you insert Javascript to display this date, it will be updated whenever you edit the (web page) file.

It's usually simpler to create an external file contains the script (javascript code) so that you can simly add two small bits of code on each web page, one that loads the script file and another to display the date. You may insert this code into a paragrph after the text "Last updated: ".

Copy the text shown below into a plain text editor and save the script files.

A. Display webpage date in format: "31 Mar 2000"

  1. First, copy the text (javascript code) in the box below. Use the highlight button to select all the code. Right click on the text and select Copy. Now open a plain text editor (Notepad, Notetab..) and start a new file (File > New) and paste the text into the editor.
  2. Save the file (File > Save as..) using the name datelastmod.js located in the same folder as your web pages.
  3. Now open your Web page in a text editor. (Don't use a web page editor unless you understand how to insert javascript code.) Locate the HEAD section between the <head> and </head> tags. Don't worry about spaces or lines between tags. Insert the following line just above the </head> tag:

    <script src="datelastmod.js" type="text/javascript"></script>

  4. In the same file, insert the code below in the BODY section where you want the date displayed. The code must be in 2 separate lines exactly as shown:

    <script language=JavaScript type="text/javascript"><!--
        document.write( date_lastmod() );//--></script>

B. Display webpage date in format: "05Apr30"

Here is a different script which displays a shorter date format. Follow the same instructions as above.

TOP back