Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Issue with date values.

Author  Topic 

venkath
Posting Yak Master

202 Posts

Posted - 2007-03-14 : 12:00:05
Hi all

I have a column with date values as
2007-09-27 00:00:00.000

i am trying to update the column by adding 1 year to this column using

DATEADD(YEAR,1,DATECOLUMN) and getting it as

2008-09-27 00:00:00.000. But i need to update it as

2008-08-26 00:00:00.000..

How can i achieve this

Thanks


Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-03-14 : 12:20:55
A year after 2007-09-27 is 2008-09-27, so that looks correct.

Is sounds like adding a year is not actually your requirement. Maybe you could explain what it really is.



CODO ERGO SUM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-14 : 13:45:24
SELECT DATEADD(DAY, 1, DATEADD(MONTH, 11, '20070927'))


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-03-14 : 17:34:47
quote:
Originally posted by Peso

SELECT DATEADD(DAY, 1, DATEADD(MONTH, 11, '20070927'))


Peter Larsson
Helsingborg, Sweden



That returns 2008-08-28, not 2008-08-26.

Add 11 months and subtract 1 day?





CODO ERGO SUM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-14 : 17:39:14
My mistake!

SELECT DATEADD(DAY, -1, DATEADD(MONTH, 11, '20070927'))


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-03-14 : 17:57:58
Maybe...
SELECT DATEADD(MONTH, - 1, CAST('2007-09-27 00:00:00.000' AS DATETIME) + 365)


*shrug*
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-14 : 18:04:48
I wonder how that would work on leap years?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-03-14 : 18:49:26
quote:
Originally posted by Peso

I wonder how that would work on leap years?


Peter Larsson
Helsingborg, Sweden



I assume Poorly.. :) But, in the absence of requirements....
Go to Top of Page
   

- Advertisement -