AdRock Posted March 13, 2008 Share Posted March 13, 2008 I have a time field in my database and I want to format the output so i jsut see HH:MM How is this done? Quote Link to comment https://forums.phpfreaks.com/topic/95971-how-to-format-time-output/ Share on other sites More sharing options...
MadTechie Posted March 13, 2008 Share Posted March 13, 2008 echo date('h:i:s A', $timestamp); see date remove the A to remove AM/PM Quote Link to comment https://forums.phpfreaks.com/topic/95971-how-to-format-time-output/#findComment-491309 Share on other sites More sharing options...
AdRock Posted March 13, 2008 Author Share Posted March 13, 2008 I tried that and now the time that comes out of the database is shown as 00:00 What have i done wrong? $depart = htmlentities($row['depart_time']); echo "<td>".$seats."</td><td>".date('H:i',$depart)."</td><td>" Quote Link to comment https://forums.phpfreaks.com/topic/95971-how-to-format-time-output/#findComment-491749 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2008 Share Posted March 13, 2008 Read the date() function in the php manual. It expects a Unix Timestamp. If you have a TIME type field, use the mysql TIME_FORMAT() function directly in a query. No slow php code is necessary. Quote Link to comment https://forums.phpfreaks.com/topic/95971-how-to-format-time-output/#findComment-491754 Share on other sites More sharing options...
l0ve2hat3 Posted March 13, 2008 Share Posted March 13, 2008 use the strtotime function $depart = htmlentities($row['depart_time']); echo "<td>".$seats."</td><td>".date('H:i', strtotime($depart))."</td><td>" Quote Link to comment https://forums.phpfreaks.com/topic/95971-how-to-format-time-output/#findComment-491794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.