Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
18:42:22
Example
The PHP code is as follows
<!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
Advertisements