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?
SQL Server DATEADD() Function The DATEADD() function adds a time/date interval to a date and then returns the date.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With