Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding to date in a strdProc

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
0
0
US
Boy, you guys are good.. OK here's another one- In a stored procedure I am passing a value such as "26 Nov 2006" If have another field where I want to add on 180 days - anyway to do it? It's ok if it;'s just a straight up datetime field value (i.e. 11/26/2007 00:00:00 AM)

[conehead]
 
With a DateTime field, you can add and subtract days the same way you do with integers.

Code:
Declare @Temp DateTime
Set @Temp = '23 Nov 2006'

Select @Temp + 180

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
you can use the dateadd funtion.

DATEADD(day, 180, @date)

- Paul
- Database performance looks fine, it must be the Network!
 
Check DATEADD() function. To add 180 days:
Code:
DATEADD(dd,180,YourDateField)


Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
George,
Does that only work for days?

- Paul
- Database performance looks fine, it must be the Network!
 
Yes. Only for days. You can get it to work time, but it gets pretty messy pretty quick.

Ex:
Code:
Declare @Temp DateTime
Set @Temp = '20061110'

Select @Temp, @Temp + 180, @Temp + .75

Notice @Temp + .75 This adds .75 days (or 18 hours). You should NOT try to do this with months or years since those time frames are inconsistent (months with 28, 29, 30 or 31 days).

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
That's good stuff George.
thanks

- Paul
- Database performance looks fine, it must be the Network!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top