RB Smissaert wrote:
Is there a way to calculate the age given the 2 dates in the standard format
yyyy-mm-dd? I could do julianday('now') - julianday(dateofbirth) and divide
by 365, but that won't be accurate enough.
It would be easy to calculate the age in the application and update the
database, but I prefer to do it all in SQL if I can.

RBS



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------


Try this (untested).

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;

HTH
Dennis Cote



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to