Page 1 of 1

[Solved] Query to return age as of December 31

Posted: Tue Jan 22, 2019 9:45 pm
by dpark29
I am attempting to run a query that will return a person's age on December 31 of the prior year. The following query returns the values I am looking for.

"SELECT ""DOB"", DATEDIFF('yy',""DOB"",'2018-12-31') As ""Age"" FROM ""tblDependents""

To make the query run without editing in future years, I would like to replace the hard-coded '2018-12-31' with a function that returns the last day of the prior year.

I am running Base with the default HSQL database engine.

Thank you for your help.

Re: Query to return age as of December 31

Posted: Tue Jan 22, 2019 10:03 pm
by FJCC
Would

Code: Select all

 SELECT year(CURDATE()) - year("DOB") -1 AS "Age" FROM "tblDependents" 
work for you?

Re: Query to return age as of December 31

Posted: Tue Jan 22, 2019 10:13 pm
by dpark29
Why yes, that does work! Brilliant...a simple and elegant solution. Thank you.