views:

10

answers:

1

I've been provided a csv file which contains an export of a client's database table. Two of the columns are dates, and in the file they're formatted as mm/dd/yyyy.

ID | ActivateDate
-----------------
1  | 05/22/2010
2  | 10/01/2010

Our mySQL database that I need to import them into has those columns defined as datetime, with a default value of null. When I use the import function in phpMyAdmin, it's setting all the date columns in the imported records to 0000-00-00 00:00:00, regardless of whether there's any value in the import file.

Can anyone tell me what I need to do to get the ActivateDate column in the database to be set to 2010-05-22 00:00:00 instead of 0000-00-00 00:00:00?

+1  A: 

If at all possible, I'd import those values into a varchar column fake_column first, and then push them over into the real column real_columnusing STR_TO_DATE.

UPDATE tablename SET real_column = STR_TO_DATE(fake_column, '%m/%d/%Y');

Reference on how to build the format string

Pekka
Thanks. So I did the import into temp varchar columns, and that worked. But when I did this: UPDATE arrc_Voucher SET `ActivatedDT` = STR_TO_DATE(ActivatedDTtmp, '%Y-%m-%d %H:%m:%s') the ActivatedDT column (the real datetime column) is still null and the myPHPAdmin query area says "0 rows affected". Any ideas?
EmmyS
@EmmyS no, if your incoming format is `05/22/2010`, you need to use the notation I showed above. It's the definition for the *incoming* data
Pekka
Thanks. I thought because you gave the reference about building the format string that I was supposed to change the format.
EmmyS
@Emmy you're welcome. I *thought* about not including it because it could be misleading :) Will listen to my thoughts next time.
Pekka