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 2005 Forums
 Transact-SQL (2005)
 Get the expiration date

Author  Topic 

d3ng
Yak Posting Veteran

83 Posts

Posted - 2009-03-04 : 23:58:31
Hi SQL Experts,

I would like to know for a script on how to get the expiration date if I only specify 3 months from my referrence date like for ex.

referrence date: 11/01/2009
Expiratiin date: 02/01/2010

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2009-03-05 : 00:01:08
declare @Expiratiin
set Expiratiin = DateAdd(m, 3, '11/01/2009')
print @Expiratiin

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-03-05 : 00:02:20
quote:
Originally posted by jhocutt

declare @Expiratiin
set Expiratiin = DateAdd(m, 3, '11/01/2009')
print @Expiratiin

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking



SMALL MODIFICATION IN UR QUERY

declare @Expiratiin DATETIME
SELECT Expiratiin = DateAdd(m, 3, '11/01/2009')
print @Expiratiin

(OR)

declare @Expiratiin VARCHAR(32)
SELECT Expiratiin = DateAdd(m, 3, '11/01/2009')
print @Expiratiin
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-05 : 01:57:16
quote:
Originally posted by Nageswar9

quote:
Originally posted by jhocutt

declare @Expiratiin
set Expiratiin = DateAdd(m, 3, '11/01/2009')
print @Expiratiin

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking



SMALL MODIFICATION IN UR QUERY

declare @Expiratiin DATETIME
SELECT Expiratiin = DateAdd(m, 3, '11/01/2009')
print @Expiratiin

(OR)

declare @Expiratiin VARCHAR(32)
SELECT Expiratiin = DateAdd(m, 3, '11/01/2009')
print @Expiratiin


Always use proper DATETIME datatype to store dates

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -