Matt Lowden

Calculate Age from Date of Birth in MySQL

November 7th 2013

Calculating someones age from a given date of birth using MySQL isn't especially complex but I've seen a few long-winded approaches to the problem so I thought I share my own method.

"SELECT FLOOR(DATEDIFF(NOW(), `date_of_birth`) / 365.25) AS 'age' FROM `users`"

The above example assumes there is a DATE field called date_of_birth in a table called users. You could expand this example to search for users between a particular date range, for instance users between the ages 27 and 33.

"SELECT FLOOR(DATEDIFF(NOW(), `date_of_birth`) / 365.25) AS 'age' FROM `users` WHERE (age >= 27 AND age <= 33)"
cialis online

Köpa Generisk viagra online i sverige