leap year birthdate

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf leap year birthdate

  • Creator
    Topic
  • #47837
    Kathy Young
    Participant

    I have a tcl that calculates age for one of our systems. One of the tests is to find out whether the person has had a birthday yet this year. I am converting the birthday to julian dates and subtracting. I found an interesting problem today…. The tcl has a problem with converting the birthday 2/29 to a julian date in a non-leap year. I am enclosing the portion of code that is not working in hopes that someone has a suggestion!

    When the brday came out to 2/29, I get a Tcl callout error {unable to convert date-time string “2/29”}

    #### Get four digit year of birth, month and day, omitting leading zeros

    set byear [string range $dob 0 3]

    if {[string range $dob 4 4] == “0”} {

    set bmonth [string range $dob 5 5]

    } else {set bmonth [string range $dob 4 5]}

    if {[string range $dob 6 6] == “0”} {

    set bday [string range $dob 7 7]

    } else {set bday [string range $dob 6 7]}

    set brday $bmonth/$bday

    set rbjday [clock format [clock scan $brday] -format %j]

    set bjday [string trimleft $rbjday 0]

    #### Have they had a birthday yet this year?

    set ageDays [expr $day – $bday]

    set ageMonths [expr $month – $bmonth]

    set ageYears [expr $year – $byear]

    if {$ageDays < 0} {set ageMonths [expr $ageMonths - 1]} if {$ageMonths < 0} {set ageYears [expr $ageYears - 1]} Thanks! Kathy

Viewing 2 reply threads
  • Author
    Replies
    • #56840
      Charlie Bursell
      Participant

      That’s because when you don’t provide a year, it assumes this year.  

      02/29/2005 is not a legal date

    • #56841
      Kathy Young
      Participant

      Charlie –

      As always, Thank You!!!

      I figured that was the problem, but didn’t think simply adding the year would resolve it. I am now using “set brday $bmonth/$bday$byear”.

      It works perfectly!

      Kathy

    • #56842
      garry r fisher
      Participant

      My answers the same as Charlie’s. Whenever you do calculations on dates unless you know for definite that you are working in the current year always include the year in your date string.

      I found out the hard way as well 😀

      Garry

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

Forum Statistics

Registered Users
5,117
Forums
28
Topics
9,293
Replies
34,435
Topic Tags
286
Empty Topic Tags
10