Reputation: 133
I want to add 1 month on a datetime on MySQL 5.1.66-0+squeeze1.
When I do that :
SELECT DATE_ADD(NOW(), INTERVAL 1 MONTH)
Result is :
2013-08-19 17:36:34
It's ok. But when I do that :
SELECT DATE_ADD("2013-07-19 17:37:00", INTERVAL 1 MONTH)
Result is :
323031332d30382d31392031373a33373a3030
Same with :
SELECT DATE_ADD("2013-07-19", INTERVAL 1 MONTH)
Result is :
323031332d30382d3139
I don't understand what's wrong :(
Thanks.
EDIT : I've tried this but error is the same.
SELECT DATE_ADD("2013-07-19", INTERVAL 31 DAY)
SELECT ADDDATE("2013-07-19", 31)
Upvotes: 0
Views: 496
Reputation: 539
Your exmple works fine for me too, it can be a configuration error... try casting the result as a DATE:
SELECT DATE(DATE_ADD('2013-07-19', INTERVAL 1 MONTH))
Upvotes: 1
Reputation: 37233
try this
SELECT DATE_ADD("2013-07-19", INTERVAL 31 DAY)
EDIT:
From MySQL 5.1.59
to 5.1.61
, a change in handling of a date-related assertion caused several functions to become more strict when passed a DATE() function value as their argument and reject incomplete dates with a day part of zero. These functions are affected: CONVERT_TZ(), DATE_ADD(), DATE_SUB(), DAYOFYEAR(), LAST_DAY(), TIMESTAMPDIFF(), TO_DAYS(), TO_SECONDS(), WEEK(), WEEKDAY(), WEEKOFYEAR(), YEARWEEK(). Because this changes date-handling behavior in General Availability-status series MySQL 5.1, the change was reverted in 5.1.62.
you can also do this
SELECT ADDDATE('2013-07-19', 31);
Upvotes: 0