How do I get "mm-dd-yyyy hh:mm:ss AM/PM" format date from mysql database with php?
1970-01-01 00:00:00 UTC
How do I get "mm-dd-yyyy hh:mm:ss AM/PM" format date from mysql database with php?
Three answers:
bob_bobbert_mcbob
2008-10-14 00:23:56 UTC
Try:
$query="SELECT CONVERT(VARCHAR,DateColumn,100) AS DateColumn FROM Table tablename";
$result=mysql_query($query);
Blackcompe
2008-10-13 23:33:46 UTC
http://www.tizag.com
Bernz
2008-10-13 19:22:08 UTC
Get your date from MySQL with a mysql_fetch_assoc function for example, then simply use the DATE php function to format the date as you see fit.
But, here's the trick: you have to use the STRTOTIME function FIRST! Aha! This will convert the "text time" from mysql into a Unix timestamp, a value that the DATE function will understand.
$mydate = ... // Get this date from mysql
echo date("m-d-Y H:i:s A", strtotime($mydate));
That's it! Good luck!
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.