I have a datetime value in mysql
'2010-12-08 16:12:12'
that I'd like to get the seconds to that date using PHP
,
so basically a PHP
equivalent of mysql
:
TIME_TO_SEC(TIMEDIFF('2010-12-08 16:12:12',now()))
If you want to convert datetime to seconds use the strtotime() from PHP. The MySQL syntax is as follows: SELECT TIME_TO_SEC(ABS(timediff('yourDateTimeValue',now()))); Now you can convert PHP datetime to seconds with the help of strtotime().
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
The strtotime() function is a built-in function in PHP which is used to convert an English textual date-time description to a UNIX timestamp. The function accepts a string parameter in English which represents the description of date-time. For e.g., “now” refers to the current date in English date-time description.
php //PHP program to convert seconds into //hours, minutes, and seconds $seconds = 6530; $secs = $seconds % 60; $hrs = $seconds / 60; $mins = $hrs % 60; $hrs = $hrs / 60; print ("HH:MM:SS-> " . (int)$hrs .
<?php
$date1 = new DateTime("2010-12-08 16:12:12");
$now = new DateTime();
$difference_in_seconds = $date1->format('U') - $now->format('U');
->format('U')
turns it into a unix timestamp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With