What is the best way to calculate the age in years from a birth date in sqlite3?
A:
There isn't a simple way to do this with SQLite out of the box.
As an alternative, you can roll your own functions that can be called from SQLite.
Marcelo Cantos
2010-06-26 13:18:56
A:
I found this that maybe would help you:
select
case
when date(dob, '+' ||
strftime('%Y', 'now') - strftime('%Y', dob) ||
' years') >= date('now')
then strftime('%Y', 'now') - strftime('%Y', dob)
else strftime('%Y', 'now') - strftime('%Y', dob) - 1
end
as age
from t;
From http://www.mail-archive.com/[email protected]/msg20525.html
Bruno Costa
2010-06-26 13:20:16
+1
A:
SELECT (strftime('%Y', 'now') - strftime('%Y', Birth_Date)) - (strftime('%m-%d', 'now') < strftime('%m-%d', Birth_Date));
This one works.
I merely ported this MySQL example: http://dev.mysql.com/doc/refman/5.0/en/date-calculations.html
kai
2010-06-26 13:37:25