Print the time an hour ago PHP?

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 



The PHP code is as follows

 Live Demo

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


This will produce the following output

One hour ago, the date = 2020-09-26 17:42:22

Updated on: 13-Oct-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started