Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to update dates in a table so that each row's date is pushed ahead by 1 day?

I have a table whose Date column needs pushing ahead by 1 day.

My update query is:

UPDATE TABLENAME
SET DATECOL=DATECOL+1

Is this correct approach? Or do I need to use CTE, for example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

;WITH CTE AS (
SELECT ID, DATECOL
FROM TABLENAME)
UPDATE T
SET T.DATECOL=CTE.DATECOL+1
FROM TABLENAME T
JOIN CTE ON T.ID=CTE.ID

>Solution :

To add a value to any part of date you can use DATEADD function. In your case the part time is DAY.

UPDATE TABLENAME
SET DATECOL=DATEADD(DAY, 1, DATECOL)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading