Reputation: 952
I have a date column in my users what I want to update with a SQL query
With the SQL query I want to add 1 month to date column in my database.
I now have:
UPDATE users SET date=(+ 1 month)
When I run this query it is not working. So my question is, how can I make this working?
Upvotes: 4
Views: 16549
Reputation: 169
The top-voted answer is good. I will add Postgres here:
Postgres:
UPDATE users
SET date = date + interval '1 month'
Upvotes: 0
Reputation: 13920
Try this:
UPDATE [TABLE_NAME]
SET [MY_DATA_FIELD] = DATEADD(MONTH, 1, [MY_DATA_FIELD])
Upvotes: -1
Reputation: 521249
You never told us the database you are using, so here are several answers:
MySQL:
UPDATE users
SET date = DATE_ADD(date, INTERVAL 1 month )
SQL Server:
UPDATE users
SET date = DATEADD(MONTH, 1, date)
Oracle:
UPDATE users
SET date = ADD_MONTHS(date, 1)
Upvotes: 19
Reputation: 3736
GETDATE() can be replaced by ur custom date value
UPDATE users SET date= DATEADD(month,1,GETDATE())
Upvotes: 0