How can I convert the following date format into a datetime format in MySQL? Right now it is stored as a varchar. Should I use a Python script, or is there an inbuilt MySQL function which will complete it?
27 07 (2009), 10:38 PM,
How can I convert the following date format into a datetime format in MySQL? Right now it is stored as a varchar. Should I use a Python script, or is there an inbuilt MySQL function which will complete it?
27 07 (2009), 10:38 PM,
like this
SELECT STR_TO_DATE('27 07 (2009), 10:38 PM', '%d %m (%Y), %l:%i %p');
Here are the specifiers: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
If the original text contains a trailing comma, you just match it in the pattern
SELECT STR_TO_DATE('27 07 (2009), 10:38 PM,', '%d %m (%Y), %l:%i %p,');
If you want to update the column, you can run an update statement like:
update mytable
set dateat = STR_TO_DATE(dateat, '%d %m (%Y), %l:%i %p,')
And don't forget to alter your field from varchar to datetime
You can use str_to_date function in mysql.
str_to_date(column,format)
Example: select str_to_date("27 07 (2009), 10:38 pm","%d %m (%Y), %l:%i %p") from table
You can use this statement
SELECT STR_TO_DATE('27 07 (2009), 10:38 PM, '%d %m(%Y),%H:%i');
This will give you 2009-07-27 22:38:00
No need to worry about PM or AM. %H will take care of that and mention 22 for 10PM and the PM will be redundant then.