Reputation: 11
what is the query to find out date which should be after 4 days of curdate
I tried
select curdate()+4
But it is giving the wrong answer.
Please help me out.
Upvotes: 1
Views: 382
Reputation: 6143
Kostas Mitsarakis is a good solution, but you also have other options:
1.using date_add function
SELECT DATE_ADD( CURDATE( ) , INTERVAL 4 DAY );
2. using adddate function
SELECT ADDDATE(curdate(), INTERVAL 4 DAY);
Upvotes: 0
Reputation: 1987
curdate()
returns either a string or an integer depending on the context it is used.
SELECT cast(curdate() as char) date_s,
cast(curdate() as unsigned integer) date_i,
curdate() + 4 bad,
curdate() + interval 4 day as "interval";
+------------+----------+----------+------------+
| date_s | date_i | bad | interval |
+------------+----------+----------+------------+
| 2015-10-28 | 20151028 | 20151032 | 2015-11-01 |
+------------+----------+----------+------------+
In your case, curdate() is returning 20151028 in number context, then adding 4 to it, to get 20151032. Using interval N day
with +/- is somewhat of a special case, as it implicitly converts the other operand to a date and does the correct date math.
Upvotes: 0