1 hour ago in php
How can I print an hour ago in PHP using Date?
So If I wanted to say "John visited last " Would print
ashleedawg 19.3k7 gold badges69 silver badges100 bronze badges asked Feb 20, 2012 at 17:29
TheBlackBenzKidTheBlackBenzKid 25.5k39 gold badges138 silver badges207 bronze badges 1
answered Feb 20, 2012 at 17:31
0
time() -> Current timestamp Time minus 3600 seconds, is the time 1 hour ago. To get the date formatted, you can look here for the options: http://php.net/manual/en/function.date.php Alternatively you could use the following format:
Though using that method can be a little clunky if you want to remove more specific units of time (Such as one day and 3 hours). Thats if I've understood what you want to do correctly that is. answered Feb 20, 2012 at 17:32
BenOfTheNorthBenOfTheNorth 2,8841 gold badge19 silver badges46 bronze badges I suppose you would be fetching date and time from mysql and the best thing to do is using mysql's DATE_FORMAT function and work out. Other wise in simple php you could do it like this $date=date("Y-m-d H:i:s", $time -3600); Better option is to use strtotime like this one $date=date("Y-m-d H:i:s", strtotime('-1 hour')); And get the work done. answered Feb 20, 2012 at 17:40
abhig10abhig10 5156 silver badges24 bronze badges Mmm, search the manual the function I used. You are missing something about PHP date/time functions...
answered Feb 20, 2012 at 17:33
lorenzo-slorenzo-s 16.2k15 gold badges48 silver badges85 bronze badges Not the answer you're looking for? Browse other questions tagged php string date time date-arithmetic or ask your own question.PHPServer Side ProgrammingProgramming
Kickstart HTML, CSS and PHP: Build a Responsive WebsiteFeatured 59 Lectures 8.5 hours Ogbemudia Terry Osayawe
More Detail 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 ExampleThe PHP code is as follows Live Demo OutputThis will produce the following output One hour ago, the date = 2020-09-26 17:42:22
AmitDiwan Updated on 13-Oct-2020 08:04:40
Previous Page Print Page Next Page Advertisements How to get 1 hour before time in PHP?$date = date("Y-m-d H:i:s", strtotime('-1 hour'));
How to add 1 hour to current time in PHP?$time = strtotime('+1 hour'); strtotime('+1 hour', $time); $time = date('H:i', strtotime('+1 hour'));
How to get hours from time in PHP?Use the Datetime class (PHP 5.3 or higher). Show activity on this post. By hours I'm assuming you mean if the time is 8PM or 20:00 hours like it is in your time string then... $date = "2011-07-26 20:05:00"; $date = strtotime($date); echo date('H', $date);
How to convert timestamp to time ago in PHP?$str . echo to_time_ago( time() - 5);
|