I would like to convert time strings (Such as 2:12:0) to decimal format in hours (ex 2:12:0 would be 2.2 hours) in PHP.
Answers
3
Try
SELECT TIME_FORMAT('10:20:00', '%h:%i %p')
Here is the SQLFiddel Demo
Saturday, May 29, 2021
2
How about this?
>>> s = '23.45678'
>>> int(float(s))
23
Or...
>>> int(Decimal(s))
23
Or...
>>> int(s.split('.')[0])
23
I doubt it's going to get much simpler than that, I'm afraid. Just accept it and move on.
Sunday, June 13, 2021
2
The easiest way is to use an NSScanner, specifically the methods scanHexInt:
or scanHexLongLong:
. Another possibility is to get the C string from the NSString and use C-style functions such as strtol
(with base 16).
Monday, August 30, 2021
2
$d = new DateTime('Wed Feb 01 2012 05:00:00 GMT-080');
echo $d->format('Y-m-dTH:i:s');
Thursday, September 2, 2021
A fairly dumb conversion from the top of my head, using explode by colon: