Yes, thanks that works. Will do a bit of testing to see which one is the fastest.
RBS -----Original Message----- From: Dennis Cote [mailto:[EMAIL PROTECTED] Sent: 22 December 2006 19:05 To: sqlite-users@sqlite.org Subject: Re: [sqlite] calculate age RB Smissaert wrote: > Thanks, it is getting close, but it doesn't quite work. > > For example this: > > select > case > when date('2002-12-22', '+' || > strftime('%Y', 'now') - strftime('%Y', '2002-12-22') || > ' years') >= date('now') > then strftime('%Y', 'now') - strftime('%Y', '2002-12-22') > else strftime('%Y', 'now') - strftime('%Y', '2002-12-22') -1 > end > as age > > Gives 3 > > Oops, I needed another set of brackets to ensure correct order of operations, and I had the comparison wrong (need <= not >=). This works: select case when date('2002-12-22', '+' || (strftime('%Y', 'now') - strftime('%Y', '2002-12-22')) || ' years') <= date('now') then strftime('%Y', 'now') - strftime('%Y', '2002-12-22') else strftime('%Y', 'now') - strftime('%Y', '2002-12-22') -1 end as age HTH Dennis Cote ---------------------------------------------------------------------------- - To unsubscribe, send email to [EMAIL PROTECTED] ---------------------------------------------------------------------------- - ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------