Calculating Age

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Calculating Age

  • Creator
    Topic
  • #47895
    LaToya Butler
    Participant

      Does anyone have a tcl proc that will calculate a patient’s age that they are willing to share?

      Thanks in advance,

    Viewing 1 reply thread
    • Author
      Replies
      • #57013
        Charlie Bursell
        Participant

          Here is a quick and dirty I threw together.  Didn’t do a lot of testing

          # Set array of days in a month

          array set dom

            -format “%Y %m %d”]

            # Separate out YYYY, MM, and DD for both the birthday and now

            regexp — {(….)(..)(..)} $birthday {} byr bmo bdy

            lassign $now nyr nmo ndy

            # Remove leading zeros so we can do math

            foreach var “byr bmo bdy nyr nmo ndy” {

               set $var [string trimleft [set $var] 0]

            }

            # Compute days

            # If Birthday days > now days the number of days is

            # 0f days in last month – birthdate + now days

            # also must take 1 away from months but remember 0 – 12

            if {$bdy > $ndy} {

               incr nmo -1

               # if 0 or less set to 12 and decrement year

               if {$nmo <= 0} {        set nmo 12        incr nyr -1    }    set nodays $dom($nmo)    # Adjust for leap year if required    if {$nmo == 2 && [expr {$nyr %4}]} {incr nodays}    set days [expr {$nodays – $bdy + $ndy}] } else {    set days [expr {$ndy – $bdy}] } # Compute months if {$bmo > $nmo} {

               set months [expr {$bmo – $nmo}]

               incr nyr -1

            } else {

               set months [expr {$nmo – $bmo}]

            }

            set years [expr {$nyr – $byr}]

            echo AGE: $years Years, $months Months and $days Days

            OK, all of you Tcl’ers.  What did I forget here  8)

            Charlie

          1. #57014
            Ayan George
            Participant

              This is a lot trickier than it seems.   Here is a good link that describes how to do this in TCL:

                http://mini.net/tcl/3189.html

              -ayan

              LaToya Butler wrote:

              Does anyone have a tcl proc that will calculate a patient’s age that they are willing to share?

              Thanks in advance,

          Viewing 1 reply thread
          • The forum ‘Cloverleaf’ is closed to new topics and replies.