RB Smissaert wrote:
Thanks to Dennis Cote I got a nice way to get the age from the date in the
form 'yyyy-nmm-dd'. It works fine when I run it on a field, but when I run
it on a literal date it gives me 100 too much:

select
case when date('2002-01-01', '+' || (strftime('%Y', 'now') - strftime('%Y', '2002-01-01')) || ' years') <= date('now') then strftime('%Y', 'now') - strftime('%Y', '2002-01-01') else strftime('%Y', 'now') - strftime('%Y', '2002-01-01') - 1 end

Why is this?

This works for me in the sqlite shell as shown below:

C:\Documents and Settings\DennisC>sqlite3
SQLite version 3.3.15
Enter ".help" for instructions
sqlite>
sqlite> select
  ...> case when
  ...> date('2002-01-01', '+' || (strftime('%Y', 'now') -
  ...> strftime('%Y', '2002-01-01')) || ' years') <= date('now')
  ...> then
  ...> strftime('%Y', 'now') - strftime('%Y', '2002-01-01')
  ...> else
  ...> strftime('%Y', 'now') - strftime('%Y', '2002-01-01') - 1
  ...> end
  ...> ;
5

How are you running this query?

Dennis Cote

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

Reply via email to