SQLite: How to calculate age from birth date

后端 未结 8 1855
独厮守ぢ
独厮守ぢ 2020-12-16 15:00

What is the best way to calculate the age in years from a birth date in sqlite3?

8条回答
  •  一个人的身影
    2020-12-16 15:15

    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/sqlite-users@sqlite.org/msg20525.html

提交回复
热议问题