Open In App

PHP getlastmod() Function

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
  
$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
  
$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
    $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
    $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


Article Tags :