Print the time an hour ago PHP?

PHPServer Side ProgrammingProgramming

To print time an hour ago, you need to subtract -1 hour. Use the strtotime() method and set the subtraction value in it i.e. -1 for 1 hour ago time, -2 for 2 hour ago time, etc.

Let’s say the current time is 

18:42:22

Example

The PHP code is as follows

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
$oneHourAgo= date('Y-m-d H:i:s', strtotime('-1 hour'));
echo 'One hour ago, the date = ' . $oneHourAgo;
?>
</body>
</html>

Output

This will produce the following output

One hour ago, the date = 2020-09-26 17:42:22
raja
Published on 13-Oct-2020 08:04:10
Advertisements