jeremykrall
jeremykrall

Reputation: 181

Simple STR_TO_DATE issue in MySQL

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

Answers (2)

Saharsh Shah
Saharsh Shah

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

fancyPants
fancyPants

Reputation: 51888

DATE_FORMAT(STR_TO_DATE('Dec 2012','%b %Y'), '%Y-%m-01')

Upvotes: 2

Related Questions