I have two dates, formated like "Y-m-d H:i:s". I need to compare these two dates and figure out the hour difference.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
The problem is that using these values the result is 167 and it should be 168:
You can convert them to timestamps and go from there:
Dividing by 3600 because there are 3600 seconds in one hour and using
round()
to avoid having a lot of decimal places.You can use
strtotime()
to parse your strings and do the difference between the two of them.Resources :
You can try this: