- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- PHP program to convert a given timestamp into time ago
- PHP print keys from an object?
- How to convert 12-hour time scale to 24-hour time in R?
- 24-hour time in Python
- Converting 12 hour format time to 24 hour format in JavaScript
- C# program to convert time from 12 hour to 24 hour format
- C++ program to convert time from 12 hour to 24 hour format
- Python program to convert time from 12 hour to 24 hour format
- Convert time from 24 hour clock to 12 hour clock format in C++
- Rafiq exercised for ( frac{3}{6} ) of an hour, while Rohit exercised for ( frac{3}{4} ) of an hour. Who exercised for a longer time?
- print() function in PHP
- PHP program to calculate the total time given an array of times
- PHP program to print the number pattern
- Set the hour for a specified date according to universal time?
- Print system time in C++

Advertisements