Click here to Skip to main content
11,501,561 members (75,112 online)
Click here to Skip to main content

Tagged as

Get an Accurate Age by Date

, 19 Feb 2010 CPOL 961
Rate this:
Please Sign up or sign in to vote.
This would work too :)As an explanation, I use datediff to get the number of days, divide that by the correct number of days in a year (keeping track of leap years, there are only 97 in every 400 years) and then FLOOR the result, thus making sure it doesn't get rounded up accidentally....
This would work too Smile | :)

As an explanation, I use datediff to get the number of days, divide that by the correct number of days in a year (keeping track of leap years, there are only 97 in every 400 years) and then FLOOR the result, thus making sure it doesn't get rounded up accidentally.

CREATE FUNCTION [dbo].[GetAge]
    (
      @Geburtsdatum DATETIME
    )
RETURNS INT
AS 
    BEGIN
        RETURN   FLOOR(DATEDIFF(dd, @Geburtsdatum, CURRENT_TIMESTAMP)/365.2425)
    END
GO

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alaric Dailey
Software Developer (Senior) Pengdows
United States United States
Currently looking for new contracts in Omaha NE or telecommute opportunities.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 19 Feb 2010
Article Copyright 2010 by Alaric Dailey
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid