Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if mySql datetime is older then 1 day from php now()

I have a record returned from MySQL that has a datetime field. What I want to do is take this value and see if it is older then 24 hours, I presume using PHP's time() to get the current time.

At the moment if I echo them out I get:

 1276954824            this is php's time()
 2010-06-19 09:39:23   this is the MySQL datetime

I presume the top one is a unix time? Have been playing around with strtotime but with not much success..

ANy help welcome!

like image 333
bateman_ap Avatar asked Jun 19 '10 13:06

bateman_ap


1 Answers

No success?

echo strtotime("2010-06-19 09:39:23");

gives me

1276940363

(mktime(9, 39, 23, 6, 19, 2010) gives the same time, so the parsing works correctly)


To get the differences in seconds, you can substract the timestamps, e.g.

$diff = time() - strtotime("2010-06-19 09:39:23");

If the differences is larger than 86400 (60*60*24) seconds, then the timestamps are more than one day apart:

if(time() - strtotime("2010-06-19 09:39:23") > 60*60*24) {
   // timestamp is older than one day
}
like image 115
Felix Kling Avatar answered Oct 18 '22 19:10

Felix Kling