dutton — 2011-06-09T12:43:06-04:00 — #1
I have a MySQL database that I need to pull for a client and work with MS Access for a bit of time. Right now, all of the dates in the database tables are being stored as integers appearing like: "1258657399".
Any idea how I can run a sql statement on the database to convert these dates to normal fomrat such as June 9, 2011?
anthonysterling — 2011-06-09T12:46:25-04:00 — #2
Sure, in PHP, you can use:-
echo date('F j, Y', $int);
dutton — 2011-06-09T12:59:58-04:00 — #3
Thanks but I am hoping to run a sql statement right from within phpmyadmin to convert all of the fields. Is that possible? I am able to change the structure of the table field to varchar from int.
anthonysterling — 2011-06-09T13:55:46-04:00 — #4
You should be changing it to a DATETIME field though, otherwise you'd be in a worse mess than you are now.
anthonysterling — 2011-06-09T13:58:17-04:00 — #5
I'm sure there's a standard way of doing this, but I'd create another table and select everything from this table (converting the columns as you go) and insert it into the new table.
Check out INSERT INTO ... SELECT ...
dutton — 2011-06-09T14:07:22-04:00 — #6
Thanks, yea I figured out how to do it in a round about way, same idea. Export table to CSV, open in Excel and create new column using formula to convert the field. Works fine since I need to massage some of the data anyways before brining it into Access.
anthonysterling — 2011-06-09T14:12:07-04:00 — #7
Please tell me you're now using a DATETIME datatype though, you'll be glad you did later down the line; trust me.
dutton — 2011-06-09T14:43:25-04:00 — #8
Yep! All is working fine, thanks!
r937 — 2011-06-09T16:16:01-04:00 — #9
sorry i missed all the excitement
to answer your original question, yes, just do this --
SELECT FROM_UNIXTIME(thesedates,'%M %e, %Y') ...