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 2008 Forums
 Transact-SQL (2008)
 Adding number of days to date

Author  Topic 

macca
Posting Yak Master

146 Posts

Posted - 2011-12-05 : 09:45:11
I am selecting column Days_On_App from tblT and adding 28 days to that as totdays. I then want to add the totdays to start_date depending on what Tno is.

SELECT DATEADD(Day, Days_On_App + 28, 'start_date') AS FutureDate
FROM tblT
WHERE(TNo = '1234')

Anyone know how to do this?

Thanks.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-12-05 : 09:53:48
Not sure what you want.
What is start_date - it looks like a literal rather than a date.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

macca
Posting Yak Master

146 Posts

Posted - 2011-12-05 : 10:06:19
start_date is a date in the DB.
Days_On_App is a int

What I want is to SELECT Days_On_App and add 28 to it then to add the total of (Days_On_App + 28) to start_date and this wil then give me a date over 28 days in teh future from start_date.

Thanks.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-12-05 : 10:12:01
SELECT DATEADD(dd, Days_On_App + 28, start_date) AS FutureDate
FROM tblT

or just
select start_date + Days_On_App + 28 AS FutureDate
FROM tblT


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

macca
Posting Yak Master

146 Posts

Posted - 2011-12-05 : 11:03:09
Thanks Nigel.

That worked.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-05 : 11:58:55
quote:
Originally posted by macca

Thanks Nigel.

That worked.


see this to understand how dates are stored and interpreted in sql server

http://visakhm.blogspot.com/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -