Calculate Age using DateDiff function in SQL Server 2008
In this article I describe how to calculate age with the datediff function.
In this article I describe how to calculate age with the datediff function. The DATEDIFF function is used to return the difference between two dates. It calculates the time between start and end time.
The syntax for using datediff() built-in function is given below:
DatePart parameter is used to calculate the difference. The datepart can be one of the following:
|Quarter of the year
|Day of the year
|Day of the week
Calculate age wit the help of datediff function:
Select getdate() as CurrentDate
Declare @CurrentDate datetime = getdate()
Declare @DOB datetime = '1986-03-15'
Select DATEDIFF( Year, @DOB, @CurrentDate) as CurrentAgeinYears