format('Y-m-d h:i:s A') in PHP not showing AM or PM

Hi all.

I have the code below in a php file that inserts $fdate into the CreateDate field in my table. The CreateDate field is set as a datatime data type, but it's not saving it with the AM or PM.

Should I instead save it as 24 hour format and store that in the database and then have another variable set as my code below to display it as a 12 hour format to the end user?
$date = new DateTime();
$date->setTimezone(new DateTimeZone('America/New_York'));
$fdate = $date->format('Y-m-d h:i:s A');

Open in new window

Thank you in advance.
Who is Participating?
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
DateTime in MySQL is date("Y-m-d H:i:s");  It does not accept AM/PM.
GaryConnect With a Mentor Commented:
Depending on how far back the dates you are storing go back you should really be using TIMESTAMP to store date/time and then converting as you need in your code.

TIMESTAMP will convert from your locale timezone to UTC, when you select back from the db then your locale will be used to convert the time into your timezone i.e. it takes care of the timezone differences and summer/winter times
And then use PHP to format the output
Ray PaseurCommented:
This article should give you enough of a foundation to move forward.  After you have read it over and tested the code snippets, please post back if you still have any questions.

Best regards, ~Ray
Ray PaseurCommented:
Please, please read the article!  There are ISO standards for this sort of thing and you can save your employer a lawsuit if you just follow the standards.
Sim1980Author Commented:
Thank you Ray I will read it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.