bolter Posted July 30, 2009 Share Posted July 30, 2009 I thought this was a pretty common problem but haven't been able to find any help online how do I transform a variable who contains a time in the format hh:mm:ss such as $var = 21:30:00 into a decimal one such as $var1 = 21.5 (the seconds can be eliminated) thanks Link to comment https://forums.phpfreaks.com/topic/168102-time-to-decimal/ Share on other sites More sharing options...
fooDigi Posted July 30, 2009 Share Posted July 30, 2009 this works on some level, although may be not that elegant of code, but see if it works for you ... <? // 12:30:00 $time = '11:49:22'; # strip the seconds $time = preg_replace('/:[0-9]{2}$/','',$time); # split hour and minutes $time_parts = explode(":",$time); # output hour ... and minutes put into decimal form echo $time_parts[0] + $time_parts[1] / 60; ?> Link to comment https://forums.phpfreaks.com/topic/168102-time-to-decimal/#findComment-886620 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.