Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL add days to a date

Tags:

sql

mysql

I have a table in MySQL. What would be the sql statement look like to add say 2 days to the current date value in the table?

UPDATE classes  SET  date = date + 1 where id = 161 

this adds one second to the value, i don't want to update the time, i want to add two days?

like image 832
Beginner Avatar asked Oct 19 '11 11:10

Beginner


People also ask

How do I add 3 days to a date in SQL?

SQL Server DATEADD() Function The DATEADD() function adds a time/date interval to a date and then returns the date.

How do I add years to a date in MySQL?

DATE_ADD() function in MySQL is used to add a specified time or date interval to a specified date and then return the date. Specified date to be modified. Here the value is the date or time interval to add.

How do I get Currentdate in MySQL?

MySQL CURDATE() Function The CURDATE() function returns the current date. Note: The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (numeric). Note: This function equals the CURRENT_DATE() function.


1 Answers

Assuming your field is a date type (or similar):

SELECT DATE_ADD(`your_field_name`, INTERVAL 2 DAY)  FROM `table_name`; 

With the example you've provided it could look like this:

UPDATE classes  SET `date` = DATE_ADD(`date` , INTERVAL 2 DAY) WHERE `id` = 161; 

This approach works with datetime , too.

like image 124
Bjoern Avatar answered Sep 28 '22 16:09

Bjoern