Reputation: 181
I am getting in a date like "Dec 2012" and want to turn it into a date like "2012-12-01". I am using STR_TO_DATE('Dec 2012','%b %Y') and it ends up looking like 2012-12-00. Any ideas how I can get it to set it to the first day of the month?
Thanks in advance.
Upvotes: 2
Views: 210
Reputation: 29051
Try this:
SELECT STR_TO_DATE(CONCAT('01 ', 'Dec 2012') ,'%d %b %Y');
OR
SELECT DATE_ADD(STR_TO_DATE('Dec 2012','%b %Y'), INTERVAL 1 DAY);
Upvotes: 0