September 27, 2008 at 6:23 am
I'm trying to take the date from one field, minus a year from it and then add a day to it.
Example: Anniversary_Date = 5/31/2009
I want to subtract a year and add a day and store that value in another field. End result should be 6/1/2008
I can't figure out how to combine the dateadd feature into one statement.
Update Name
set bill_begin = DATEADD ( year , -1, anniversary_date ) (this takes care of the year... can I manipulate the day as well in the same statement?)
Thanks
Roger
September 27, 2008 at 6:50 am
Try this:
DECLARE @date DATETIME
SELECT @date = '5/31/2009'
SELECT @date = DATEADD(year, -1, @date) + 1
SELECT @date AS date
/*
date
-----------------------
2008-06-01 00:00:00.000
*/
.
September 27, 2008 at 8:45 am
Thanks! I get trying to use the DATEADD function again in the same line.
Roger
September 27, 2008 at 4:48 pm
Roger Abram (9/27/2008)
Thanks! I get trying to use the DATEADD function again in the same line.Roger
... and that will work, also... although it's a bit uglier...
DECLARE @date DATETIME
SELECT @date = '5/31/2009'
SELECT @date = DATEADD(day,1,DATEADD(year, -1, @date))
SELECT @date AS date
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply