Skip to content
Advertisement

How to remove minutes from a time if they are zero (09:00 to 9am)

I need to convert 4 digit times to am/pm and can do that using this function: date(“g:ia”,$starttime) which converts 08:30 to “8:30am”.

But I want times that are on the hour to hide the zero minutes. So I want 09:00 to be displayed as “9am”. Is there something built into php to easily do this?

Advertisement

Answer

$date = date("g:ia",$starttime);
$date = str_replace(":00", "", $date);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement