Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print the time an hour ago [duplicate]

Possible Duplicate:
Given a time, how can I find the time one month ago

How can I print an hour ago in PHP using Date?

$date=date("Y-m-d H:i:s");
$time(-1, now);
$result=$date.$time;

So If I wanted to say "John visited last "

Would print

John visited last 20th Feb 2012, 17.26

like image 759
TheBlackBenzKid Avatar asked Feb 20 '12 17:02

TheBlackBenzKid


2 Answers

$date = date('Y-m-d H:i:s', strtotime('-1 hour'));
echo 'John visited last ' . $date;
like image 142
Paul Avatar answered Oct 20 '22 23:10

Paul


$date = date("Y-m-d H:i:s", time() - 3600);

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:

$date = date("Y-m-d H:i:s", strtotime('-1 hour'));

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.

like image 10
BenOfTheNorth Avatar answered Oct 20 '22 22:10

BenOfTheNorth