Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
19:24:15 06/13/2013

I need to have it converted to be in 12-hour AM/PM without the seconds. So the above time would be 7:24 PM. The date should remain in mm/dd/yyyy format. Is there an elegant way to do this in PHP (not MySQL)? Thanks! 


What I have tried:

I try in html tags but did not work what pattern or format in php
Posted
Updated 27-Feb-16 22:58pm

Quote:
How to convert 24 hours to 12 hours what pattern or format in php

It is formatting more than a convert.
-First you need to store the value in a variable of type DateTime
-Then it is a matter of formatting when you output the value.
This is exactly what is doing the 2 lines of code in solution 1.
 
Share this answer
 
Try:
$datetime = '19:24:15 06/13/2013'; 
echo date('h:i A m/d/Y', strtotime($datetime));

PHP: date - Manual[^]
PHP: strtotime - Manual[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900