Revision [241]

Last edited on 2009-06-29 17:01:18 by SethKrieger
Additions:
======Birthdays and Ages ======
How do I calculate current ages? I am trying to create a list of active patients 18 and younger with their ages and birthdays.
You might think that you could use the standard SQL function called DATEDIFF to just subtract the years, but that won't give you an accurate age if the current date is earlier in the year than the birthday. To get a true age calculation, use the custom function "AGEINYEARS" that SOS has added to your database. It takes two parameters, the date of birth and the reference date on which you want to calculate age. Most of the time that will be CURRENT DATE, but you can use a different date if desired.
SELECT
lastname as "Last Name",
firstname as "First Name",
id,
AGEINYEARS(dob,CURRENT DATE) AS "Current Age" ,
DATEFORMAT (dob, 'MM-DD-YYYY') AS "Date of Birth"
FROM
patients
WHERE
flag = 0 /* active patients only */
AND dischargedate IS NULL /* no discharge date has been entered */
AND "Current Age" <= 18 /* only patients younger than 18 years of age */
ORDER BY lastname,firstname, id
Deletions:
======Query Title ======
comments here appear in italics
paste your tested query here


Revision [240]

The oldest known version of this page was created on 2009-06-29 16:54:33 by SethKrieger [Cloned from NewQuery]
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki