lee_jd
asked on
Convert MYSQL DATETIME to short date time
I've extracted a table from mySQL. One of the fields is of type DATETIME.
I'm trying to convert this to a short date and time with code below.
However, the date returned with this code is 01/01/70 1:33 (AM) for all dates.
What am I doing wrong? Would it better to format the data in the SQL query - if so any ideas how to do this?
I'm trying to convert this to a short date and time with code below.
However, the date returned with this code is 01/01/70 1:33 (AM) for all dates.
What am I doing wrong? Would it better to format the data in the SQL query - if so any ideas how to do this?
while ($table = $result->fetch_row()) {
//
//
//
field4 = date("d/m/y g:i (A)", $table[3]);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can do the date formatting either way. The choice might depend on whether you need to collate or compare the date values elsewhere in the PHP code. If you needed the ISO8601-format date, you might select the DATETIME field directly and make a "pretty date" conversion in PHP. That would probably be my instinctive choice. But either way is likely to get you the right values. Cheers, ~Ray
ASKER
Top class