Saturday, September 28, 2024
Google search engine
HomeLanguagesPHP getlastmod() Function

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




<?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=" neveropen";
  
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  neveropen
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 =" neveropen";
    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 neveropen
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 =" neveropen";
    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 neveropen
This page was Last modified on 13:57:47 pm

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

RELATED ARTICLES

Most Popular

Recent Comments