Thursday, October 23, 2025
HomeLanguagesHow to get the time of the last modification of the current...

How to get the time of the last modification of the current page in PHP?

Sometimes, we need to get the last modification time of the current page in PHP for different uses. Since we are using PHP, we can easily get the last modification time of the current page by using getlastmod() PHP function.

Using getlastmod() Function: The getlastmod() function is used to get the last modification time of the current page. This function is easy and powerful.

Syntax:

$last_modification=”Last modified on: ” . date (“F d Y H:i:s.”, getlastmod());

Example :The following is the complete code to get and show the last modification time of the current page.

PHP




<?php
    
// To Get the last modification time.
$last_modification="Last modified: " . date ("F d Y H:i:s.", getlastmod());
  
// To Show the last modification time.
echo $last_modification;
  
?>


Output

Last modified: February 25 2021 12:40:34.

Note: We can directly use it as the following.

echo "Last modified: " . date ("F d Y H:i:s.", getlastmod());

Using filemtime() Function: The filemtime() function in PHP is an inbuilt function that is used to return the last time of a specified file when its content was modified.

Example:

PHP




<?php 
    
// checking last time the contents 
// of a file were changed 
echo filemtime("index.html.txt"); 
    
// checking last time the contents of 
// a file were changed and formatting 
// the output of the date  
echo "Last modified: ".date("F d Y H:i:s.",  
                      filemtime("index.html")); 
?> 


Output:

Last modified: February 13 2021 13:01:35.
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS