XJTRy Posted October 20, 2012 Share Posted October 20, 2012 I parse .csv data and echo into a table. Pretty basic stuff. Two columns in the csv represent departure time and arrival time. They are simply echoed as 4 character strings from an array (ex. 0725) and I want to convert them to the proper time format using hours and minutes (ex. 07:25). What's the simplest/correct way to do so? Thanks! Link to comment https://forums.phpfreaks.com/topic/269717-convert-4-character-string-to-hm-format/ Share on other sites More sharing options...
scootstah Posted October 20, 2012 Share Posted October 20, 2012 I'd say insert a colon in the middle (07:25), and then use strtotime to get a UNIX timestamp from that. Something like: $time = '0725'; $time = strtotime(implode(':', str_split($time, 2))); EDIT: You only need the strtotime() if you want to use something like date. Link to comment https://forums.phpfreaks.com/topic/269717-convert-4-character-string-to-hm-format/#findComment-1386584 Share on other sites More sharing options...
XJTRy Posted October 20, 2012 Author Share Posted October 20, 2012 Thanks! I actually wasn't headed down that path, but it works great and adds functionality in other areas. Link to comment https://forums.phpfreaks.com/topic/269717-convert-4-character-string-to-hm-format/#findComment-1386591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.