2009-10-05 18:11:08
2009-10-05 18:07:13
This should generate 235,how to do it ?
You can convert them to timestamps and go from there: $hourdiff = round((strtotime($time1) - strtotime($time2))/3600, 1);
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 date_diff() function is an inbuilt function in PHP that is used to calculate the difference between two dates. This function returns a DateInterval object on the success and returns FALSE on failure.
With DateTime objects, you can do it like this:
$date = new DateTime( '2009-10-05 18:07:13' ); $date2 = new DateTime( '2009-10-05 18:11:08' ); $diffInSeconds = $date2->getTimestamp() - $date->getTimestamp();
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