Skip to content
Related Articles

Related Articles

Improve Article

PHP getlastmod() Function

  • Last Updated : 26 Jul, 2021

The getlastmod() function is used to get the time of the last modification of the main script of execution. To show the last modification time of the current page, we use the following.

Syntax:

int|false getlastmod()

Parameters: This function does not accept any parameter.

Return Value: It returns the time of the last modification of the current page. The value returned is a Unix timestamp, suitable for the date(). It returns false on error.

 



Example 1:

PHP




<?php
  
$txt = "PHP";
  
echo "I love $txt! \r\n";
echo "This page was last modified on ".
    date("d F Y h:i:s ",getlastmod());
  
?>
Output
I love PHP! 
This page was last modified on 16 June 2021 07:06:06 

Example 2:

PHP




<?php
  
$txt = "Akshit";
$GFG=" GeeksforGeeks";
  
echo "I am $txt and I love $GFG\r\n";
echo "This page was Last modified on " 
    . date("d F Y h:i:s ",getlastmod());
  
?>
Output
I am Akshit and I love  GeeksforGeeks
This page was Last modified on 16 June 2021 07:10:46 

Example 3: The following code is modified using the date(“h:ia”) function.

PHP




<?php
    $txt = "This is changed text";
    $GFG =" GeeksforGeeks";
    echo "$txt of $GFG\r\n";
    echo "<br>";
    echo "This page was Last modified on "
        . date("h:ia ",getlastmod());
?>

Output:

This is changed text of GeeksforGeeks
This page was Last modified on 01:48pm

Example 3: The following code modified using the date(“H:i:s a”) function.

PHP




<?php
    $txt = "This is new date format";
    $GFG =" GeeksforGeeks";
    echo "$txt of $GFG\r\n";
    echo "<br>";
    echo "This page was Last modified on "
        . date("H:i:s a",getlastmod());
?>

Output:

This is new date format of GeeksforGeeks
This page was Last modified on 13:57:47 pm

Reference: https://www.php.net/manual/en/function.getlastmod.php




My Personal Notes arrow_drop_up