Calclulate age from DOB (date of birth)

Added by iNTERFACEWARE

This function calculates age from DOB, it returns years, months and partial years (i.e., 17, 3, 17.296272).

Source Code
require 'dateparse'
local age = require 'age'


function main(Data)
   local Msg = hl7.parse{vmd ='example\\demo.vmd', data = Data}
   
   -- using dateparse allows common date formats
   local AgeYr, AgeMth, AgeDec = age.getAge(Msg.PID[7][1]:D())
   trace(AgeYr, AgeMth, AgeDec)

   AgeYr, AgeMth, AgeDec = age.getAge('19980210')
   trace(AgeYr, AgeMth, AgeDec)

   AgeYr, AgeMth, AgeDec = age.getAge('1998-02-10')   
   trace(AgeYr, AgeMth, AgeDec)   
end
Description
This function calculates age from DOB, it returns years, months and partial years (i.e., 17, 3, 17.296272).