How can add 1 year to a date value stored in the DB as varchar (format: “2011.03”)?
I’m trying with this, but returns NULL 🙁
DATE_FORMAT(DATE_ADD(STR_TO_DATE('2011.03', '%Y.%m'), INTERVAL 1 YEAR),'%Y.%m')
Thank you very much!
edit.: this is the query i want to use in:
SELECT DISTINCT column FROM table WHERE column BETWEEN '2011.03' AND DATE_FORMAT(DATE_ADD(STR_TO_DATE('2011.03', '%Y.%m'), INTERVAL 1 YEAR),'%Y.%m') ORDER BY column DESC
(“2011.03” is a parameter value and comes outside)
What you are trying is giving correct result
Try :
it’s giving
2012.03.Edit:
You can use below trick to make it workable in mysql version > 5.0
Add month with date because in Mysql version > 5.0
str_to_date()sometimes would return NULL if the %D format specifier was not the last specifier in the format string input.Try below: