Tim B
Tim B

Reputation: 319

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?

Upvotes: 1

Views: 716

Answers (1)

Auftraggeber
Auftraggeber

Reputation: 66

$date = date("g:ia",$starttime);
$date = str_replace(":00", "", $date);

Upvotes: 5

Related Questions