1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Automatically display when a file was last modified on your website


If your website contains time sensitive information (or even if it doesn't) you may want to display the last time a file was modified on your website. This gives users an accurate idea of how up to date the information on a page is. You can automatically draw this information from the file itself using the filemtime () PHP function.

The filemtime () PHP function retrieves the Unix timestamp from the file itself of when the file was last being written. This can show us when a file was last modified.

Example Code:

$last_mod = filemtime("filename.php");
print("Last Edited on ");
print(date("m/j/y h:i", $last_mod));

Be sure to replace "filename.php" with the actual name of the file you are checking on. This could be the file where you are printing the last modified date, or it could be an outside file you are checking on.

  1. About.com
  2. Technology
  3. PHP / MySQL
  4. Learn PHP
  5. Display File Last Modified With a PHP Script and filemtime

©2014 About.com. All rights reserved.