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
 General SQL Server Forums
 New to SQL Server Programming
 subtracting 16 days from datetime; show days only

Author  Topic 

joebuzz83
Starting Member

16 Posts

Posted - 2012-01-06 : 12:03:48
Hi all,

I am trying (and trying and trying....) to manipulate a date within a complex script. I am trying to do the following within my initial select statement:

1. subtract 16 days from a datetime column
2. get the result of the new datetime and minus that from todays day
3. extract only the days from the final datetime

So if I have an intial datetime of 2011-01-17 23:52:69.999,
I will need to subtract 16 days resulting in a value of 2011-01-01 23:52:69.999
then I will need to take that value and subtract it from todays date,
then i will need to extract how many days have passed from the datetime to today.

I was trying to manipulate the datetime using this:
, (case when t.reason_codes_display_only!=''
then (select datediff(day, (DATEadd(DAY, -16, (Convert(varchar,convert(datetime,t.tran_date),101), GETDATE())))))
else '' end) as 'Days from Denial Date'--13

Would one of you kind folks please help me out? I'm lost.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-06 : 12:34:41
Would this work?
DATEDIFF(dd,DATEADD(dd,-16,t.tran_date),GETDATE())
Go to Top of Page

joebuzz83
Starting Member

16 Posts

Posted - 2012-01-06 : 13:26:19
You are great! Thanks.....

I tried that form as well, but it wouldn't work. i must have had something wrong and didn't notice. Thanks so much!
Go to Top of Page
   

- Advertisement -