How to calculate the exact age of the database based on date of birth

  There are many online people are asking how to calculate the age based on date of birth, to answer a lot of people, but most of them are cut in a way to count years of age, this error is too big, we now calculate precise idea of age They are: after years cut, and then compare monthly day, month, less than a day, minus a year on OK.

SQL Server calculate the exact ages:
the SELECT DATEDIFF (year, Birtyday, getdate ()) - Case the when DATEDIFF (Day, DATEADD (year, DATEDIFF (year, Birtyday, getdate ()), Birtyday), getdate ())> = 0 the then End the else. 1 0

the MySQL accurately calculated Age:
SELECT year (now ()) - year (Birthday) - (the DATE_FORMAT (the nOW (), '% m% D') <the DATE_FORMAT (Birthday, '% m% D'))

Released four original articles · won praise 5 · views 10000 +

Guess you like

Origin blog.csdn.net/feiyingnet/article/details/4673588