I try to insert an csv file into mysql table. And one of the column in the file have date format like this: 3/15/2013 17:41:38 . Is it possible to insert the column, and change the date format become like this: 2013-03-15 17:41:38 ?
Thanks before
I try to insert an csv file into mysql table. And one of the column in the file have date format like this: 3/15/2013 17:41:38 . Is it possible to insert the column, and change the date format become like this: 2013-03-15 17:41:38 ?
Thanks before
You can use STR_TO_DATE for your insert, so you can put:
STR_TO_DATE( '3/15/2013 17:41:38', '%c/%e/%Y %H:%i:%s' )
as your date column.
The format reffers to the format of the input string, and the output format will be the standard MySQL date format as you need.
The output should be as:
mysql> select STR_TO_DATE( '3/15/2013 17:41:38', '%c/%e/%Y %H:%i:%s' );
+----------------------------------------------------------+
| STR_TO_DATE( '3/15/2013 17:41:38', '%c/%e/%Y %H:%i:%s' ) |
+----------------------------------------------------------+
| 2013-03-15 17:41:38 |
+----------------------------------------------------------+
1 row in set (0.08 sec)
mysql> select STR_TO_DATE( '3/15/2013 17:41:38', '%c/%e/%Y %H:%i:%s' ); +----------------------------------------------------------+ | STR_TO_DATE( '3/15/2013 17:41:38', '%c/%e/%Y %H:%i:%s' ) | +----------------------------------------------------------+ | 2013-03-15 17:41:38 | +----------------------------------------------------------+ 1 row in set (0.08 sec) (Sorry, I can't properly format the output on a comment.