Reputation: 13
I have this text string that I need to convert to a date:
June 2012
It's okay if the data is always just "01"
What's best approach to changing that "June 2012" string into a date?
Thanks in advance!
Upvotes: 0
Views: 49
Reputation: 65244
SELECT STR_TO_DATE(CONCAT('1 ','June 2012'),'%d %M %Y');
so the pattern is
SELECT STR_TO_DATE(CONCAT('1 ',$YOUR_DATE_STRING),'%d %M %Y');
Upvotes: 1
Reputation: 23719
Code:
SELECT STR_TO_DATE(CONCAT('01 ', 'June 2012'), '%d %M %Y');
Result:
2012-06-01
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date
Upvotes: 1