Given two dates, how do I determine an age?
There are a few considerations here. Most people funnel into big mathematical equations, dividing the datediff in days by 365.333333333 and doing all kinds of logic to equate that to an age. In addition, we need to be wary of leap years and treat those cases differently. While a leap year baby's true age might technically be in the single digits, the more important piece of data (usually) is that x number of years have passed since they were born. Here is an example in VBScript:
And here is an example in T-SQL, which also accounts for leap year birthdays (and thanks to Steve Kass for correcting my earlier script):
(You'll probably want to put this into a function, rather than calculating it inline, if you're using SQL Server 2000.)
Finally, here is a solution in Access, given a table named DOBs with a column named dob (with only date, and no time information -- or time set to midnight):
Related ArticlesCan I get millisecond accuracy in ASP?
Can I make VBScript format dates for me?
Could I get a little help with dates?
Given a date, how do I find the beginning and end of that week?
How do I calculate dates, such as the first day of the month?
How do I convert a DATEDIFF to days, hours, and minutes?
How do I convert a timespan, in seconds, to HH:MM:SS?
How do I convert local time to UTC (GMT) time?
How do I count the number of business days between two dates?
How do I delimit/format dates for database entry?
How do I determine the number of seconds since 1/1/1970?
How do I display time in military format?
How do I implement a calendar / datepicker in ASP?
How do I select time only from a DATETIME column?
Why do I have problems inserting NOW() into a database?