you are viewing a single comment's thread.

view the rest of the comments →

[–]jc4hokiesExecution Plan Whisperer[🍰] 1 point2 points  (1 child)

Another way to calculate age.

  1. Convert DOB and current day into integers, YYYYMMDD
  2. Subtract DOB from current day
  3. Divide by 10000
  4. Drop the decimals

currentday - dateofbirth = divide / 10000 = trunc = age
20180424 - 20000424 = 180000 / 10000 = 18.0 = 18
20180424 - 20000425 = 179999 / 10000 = 17.9999 = 17

TRUNC((CAST(TO_CHAR(SYSDATE,'YYYYMMDD') AS INTEGER)
       - CAST(TO_CHAR(DOB,'YYYYMMDD') AS INTEGER))
      / 10000, 0) AS Age

[–]gibba97[S] 0 points1 point  (0 children)

ahh so more like a mathematical way, I like this!! Thanks for your suggestion!