Reputation: 332
I have created a code like
<?=date('h:m A',strtotime('09:30:00'))?>
I am getting an output like 09:12 AM. The actual result will be 09:30 AM. Why getting a result like the above?
Upvotes: 0
Views: 142
Reputation: 318508
A quick look at the documentation of the date()
function shows the mistake in your code:
m
Numeric representation of a month, with leading zeros
i
Minutes with leading zeros
So you need i
for the minute. The whole format string would be 'h:i A'
However, it would be much better if you didn't use the date
function but strftime
which uses standardized format variables:
<?=strftime('%I:%M %p', strtotime('09:30:00'))?>
Upvotes: 7