Jump to content

Convert 4 Character String To H:m Format


XJTRy

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.