1

I'm using MySQL 5.6 and I have datetime stamps like one of this: 2015年01月28日 08:30:02:843000. Currently, they are stored as strings. I tried to alter the table to make this into datetime objects but the command failed. I'm rough with SQL, what would be the query to convert these to datetime objects? Do I need to remove the milliseconds somehow? Or convert the last colon to a period?

ApproachingDarknessFish
14.4k8 gold badges42 silver badges81 bronze badges
asked Jan 30, 2015 at 19:51
5
  • 2
    What RDBMS are you using? Commented Jan 30, 2015 at 19:53
  • well, if it's sql server this would help stackoverflow.com/questions/19025192/… Commented Jan 30, 2015 at 19:58
  • possible duplicate of Unable to convert varchar to datetime in MySql Commented Jan 30, 2015 at 21:03
  • 1
    I'd guess you're reinforcing the general principle that it's a good idea to store the data in its natural format (i.e. a date) let the import and export procedures handle converting to and from the source and usage. It also helps the database manipulate the data more efficiently, in most cases. Commented Jan 31, 2015 at 5:55
  • Yea I only have a couple days of data, I'll probably just scrap it and fix it. Thanks! Commented Jan 31, 2015 at 5:56

1 Answer 1

2

http://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_str-to-date 'STR_TO_DATE(str,format)'

Should do the trick for you. What you want to do A) Create New Field (date) B) UPDATE table set new field convert(old field) C) You're done

answered Jan 31, 2015 at 5:07
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.