Ask Your Question
4

What is the method to derive age from a birth date in SQLite?

asked 2021-06-25 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-20 16:00:00 +0000

devzero gravatar image

The method to derive age from a birth date in SQLite is as follows:

SELECT strftime('%Y', 'now') - strftime('%Y', birthdate) - (strftime('%m-%d', 'now') < strftime('%m-%d', birthdate)) AS age

Here, the strftime() function is used to extract the year, month, and day from the birth date and the current date. Then, the year difference between the two dates is calculated and adjusted for the birth month and day. Finally, the result is returned as the age.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-25 11:00:00 +0000

Seen: 8 times

Last updated: Oct 20 '21