SQL 2000 UDF to return the age of a person, given a date of birth | Database Journal

SQL 2000 UDF to return the age of a person, given a date of birth

Written By
Karl Granbow
Karl Granbow
Apr 6, 2001
1 minute read

SQL Server 2000 script for creating a user defined function that returns
the age of person whose date of birth has been provided.

To use the function:

SELECT dbname.dbo.GetAge(DateOfBirth, GETDATE()), column1, column2….,

FROM TableName

Alternatively

SELECT * FROM TableName

WHERE dbname.dbo.GetAge(DateOfBirth, GETDATE()) > n

Unfortunately SQL Server 2000 doesn’t allow for the use of GETDATE() within
user defined functions so it needs to be passed explicitly as a parameter.

Get the Script

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.