How to convert a patient birth date to days?

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf How to convert a patient birth date to days?

  • Creator
    Topic
  • #55724
    Amdy Diene
    Participant

      I need to convert a patient birth date to days and use the result to check for patient age.  I am using the code below in the pre proc in the xlate.  the result I am getting for a birth date of ‘20110209’ is 17697, and I know for a fact this is not the correct number of days from 02/09/2011 til now.

      lassign $xlateInVals pid_7_1 dob

      set dob [string range $pid_7_1 0 0]

      set dob [expr [clock scan $dob] / 60 / 60 / 24]

      echo “birthdate: $pid_7_1; dob: $dobn”

      set xlateOutVals $dob

      Need assistance on this one.  I have stared at this code for two days and made several changes and switches but nothing seems to give me what I need.

    Viewing 3 reply threads
    • Author
      Replies
      • #86313
        Jim Kosloskey
        Participant

          My guess is your clock scan of dob is giving the number of days from epoch time to the dob.

          If you want the number of days from dob to today you could also do a clock scan for today giving you the number of days from epoch time to today.

          Then subtract the (dob from today) to get the number of days between dob and today.

          I do not have an environment where I can test this but I think this is the case.

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #86314
          Amdy Diene
          Participant

            You are right Jim, and I change the code to below and it is working.

            lassign $xlateInVals pid_7_1 dob

            set dob [string range $pid_7_1 0 7]

            set date1 [clock scan $dob]

            set date2 [clock seconds]

            set elapsedDays [expr {($date2 – $date1) / (60 * 60 * 24)}]

            echo “birthdate: $pid_7_1; dob: $elapsedDaysn”

            set xlateOutVals $elapsedDays

          • #86315
            Jim Kosloskey
            Participant

              My guess is your clock scan of dob is giving the number of days from epoch time to the dob.

              If you want the number of days from dob to today you could also do a clock scan for today giving you the number of days from epoch time to today.

              Then subtract the (dob from today) to get the number of days between dob and today.

              I do not have an environment where I can test this but I think this is the case.

              email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

            • #86316
              Amdy Diene
              Participant

                Yes you are right.  clock scan today and clock seconds give me the same result.

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