John
John

Reputation: 952

Update the date in the database with +1 month

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

Answers (4)

Will Hu
Will Hu

Reputation: 169

The top-voted answer is good. I will add Postgres here:

Postgres:

UPDATE users
SET date = date + interval '1 month'

Upvotes: 0

daniele3004
daniele3004

Reputation: 13920

Try this:

UPDATE [TABLE_NAME]
SET [MY_DATA_FIELD] = DATEADD(MONTH, 1, [MY_DATA_FIELD])

Upvotes: -1

Tim Biegeleisen
Tim Biegeleisen

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

Atul Chaudhary
Atul Chaudhary

Reputation: 3736

GETDATE() can be replaced by ur custom date value

UPDATE users SET date= DATEADD(month,1,GETDATE())

Upvotes: 0

Related Questions