Jump to content

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.

Edited by scootstah
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.