Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Add 30 days to a value in the table

Tags:

datetime

mysql

I'm trying to use the ADDDATE function on a value in the table.

UPDATE credit SET addOns=ADDDATE(addOns, INTERVAL 30)

addOns is where I store the datetime. Why can I not add 30 days?

I also tried

UPDATE credit SET addOns=ADDDATE(SELECT addOns FROM credit, INTERVAL 30)
like image 947
Frank Vilea Avatar asked Sep 01 '11 22:09

Frank Vilea


People also ask

How can I add 15 days to current date in MySQL?

Use the DATE_ADD() function if you want to increase a given date in a MySQL database. In our example, we increased each start date by two days. This function takes two arguments.

How do I get last 30 days data in SQL?

How do I find last 30 days in SQL? SELECT * FROM product WHERE pdate >= DATEADD(day, -30, getdate()).

Why is DATE_ADD () used?

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. This value can be both positive and negative.


1 Answers

If you specify INTERVAL, you must specify the unit; if you don't specify INTERVAL it will default to days.

UPDATE credit SET addOns=ADDDATE(addOns, INTERVAL 30 DAY)

Without interval keyword.

UPDATE credit SET addOns=ADDDATE(addOns, 30)
like image 80
Suroot Avatar answered Nov 16 '22 02:11

Suroot