Reputation: 2077
In my php file i select from a mysql db a datetime field. I need to know, in seconds (numeric value) the difference between this value and now()
e.g.:
value from db: 2014-02-02 16:58:22
Now is: 2014-02-03 16:59:00
Result: 86438
Thanks in advance
Upvotes: 0
Views: 56
Reputation: 2335
If you want to calculate this in PHP, you can do this using the DateTime
object
$First = new DateTime('2014-02-02 16:58:22');
$Second = new DateTime('2014-02-03 16:59:00');
echo "The difference is " . ($Second->getTimestamp() - $First->getTimestamp()) . " seconds";
Which will output:
The difference is 86438 seconds
Upvotes: 0
Reputation: 4629
Try This http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timestampdiff
SELECT TIMESTAMPDIFF(SECOND, '2014-02-02 16:58:22', '2014-02-03 16:59:00')
Upvotes: 1