********************Adding or Subtracting Dates********************
If the requirement is to calculate the age of a person six months from now, dateadd function can help
Select BirthDate, DateDiff(year, BirthDate, Dateadd(month, 6, getdate())) as BirthDateAfterSix from HumanResources.Employee Order By 1 Desc
subtracting dates is equally easy:
Select BirthDate, DateDiff(year, BirthDate, Dateadd(month, -6, getdate())) as BirthDateAfterSix from HumanResources.Employee Order By 1 Desc

Monday, April 16, 2007
SQL Adding or Subtracting Dates
Labels:
Adding Dates,
Dateadd,
SQL Server 2005,
Subtracting Dates,
Sybase
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment