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.
| Author |
Topic |
|
venkath
Posting Yak Master
202 Posts |
Posted - 2007-03-14 : 12:00:05
|
| Hi allI have a column with date values as2007-09-27 00:00:00.000i am trying to update the column by adding 1 year to this column usingDATEADD(YEAR,1,DATECOLUMN) and getting it as2008-09-27 00:00:00.000. But i need to update it as2008-08-26 00:00:00.000..How can i achieve thisThanks |
|
|
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 |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-14 : 13:45:24
|
| SELECT DATEADD(DAY, 1, DATEADD(MONTH, 11, '20070927'))Peter LarssonHelsingborg, Sweden |
 |
|
|
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 LarssonHelsingborg, Sweden
That returns 2008-08-28, not 2008-08-26.Add 11 months and subtract 1 day?CODO ERGO SUM |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
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* |
 |
|
|
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 LarssonHelsingborg, Sweden |
 |
|
|
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 LarssonHelsingborg, Sweden
I assume Poorly.. :) But, in the absence of requirements.... |
 |
|
|
|
|
|
|
|