Link to home
Start Free TrialLog in
Avatar of lee_jd
lee_jdFlag for Afghanistan

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?
while ($table = $result->fetch_row()) {
//
//
//
field4 = date("d/m/y g:i (A)", $table[3]);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of lee_jd

ASKER

Top class