Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Age Last Birthday Calculation

RSS
Modified on Wed, Jan 07, 2015, 11:00 AM by Administrator Categorized as SQL Server

SQL Server (T-SQL)

create function dbo.AgeLastBirthday(@dob date)
returns int as begin

declare @today date = getdate()

declare @Years  int = year(@today) - year(@dob)

declare @LastBirthday date = dateadd(year, @Years, @dob)

if @LastBirthday > @today begin
    set @Years = @Years - 1
    --set @LastBirthday = dateadd(year, @Years, @dob)
    end

return @Years

end

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2018, Patrick Jasinski.