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.
Sim1980Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
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
0
Dave BaldwinFixer of ProblemsCommented:
DateTime in MySQL is date("Y-m-d H:i:s");  http://us3.php.net/manual/en/function.date.php  It does not accept AM/PM.  http://dev.mysql.com/doc/refman/5.5/en/datetime.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Best regards, ~Ray
0
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.
0
Sim1980Author Commented:
Thank you Ray I will read it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.