2 Replies Latest reply on Jul 22, 2012 12:04 PM by charlesyates01

    Converting military time to readable text

    charlesyates01

      Title

      Converting military time to readable text

      Post

      I followed a previous forum thread detailing a calcuation to convert military time to text.  It works great... but only if you're at the top of an hour.  In other words, the hours convert just fine, as does the am/pm.  However the minutes won't work at all.  If your minutes fall between :01 and :59 the resulting minutes are alway :00.  I will include the formula below in hopes that someone can help me figure out how to get my military time to read 3:14 pm instead of 3:00 pm.  Any help is greatly appreciated.

       

      Let ( [ 
      theData=  militaryTime 
      ; theHour= Left ( theData ; 2 ) 
      ; theMinute= Right ( theData ; 2 )
      ; theSeconds= "00" 
      ; theTime= Time ( theHour ; theMinute ; theSeconds ) 
      
      ; theResultingHours= Hour ( theTime ) 
      ; theResultingMinutes= Minute ( theTime ) 
      
      ; theSuffix= Case ( theResultingHours  ≥  12 ; " pm" ; " am" ) 
      ; theFInalHours = Mod ( theResultingHours - 1 ; 12 ) + 1 
      ; theFinalMinutes= Right ( "00" & theResultingMinutes ; 2 ) 
      
      ; result= theFinalHours & ":" & theFinalMinutes & theSuffix 
      
      ]; 
      result
      )

        • 1. Re: Converting military time to readable text
          philmodjunk

          I see no need for this complex set of calculations.

          If you store the time into a time or time stamp field, you can simply use data formatting to display the time in 12 hour format with am and pm designations and none of this is required to do that.

          You can enter 22:00 and when you exit the field it will display as: 10:00 pm

          • 2. Re: Converting military time to readable text
            charlesyates01

            You are correct.  I was, however, trying to get a result that yields a 'text' answer to incorporate into a text field.  Since posting my original question this morning, I have actually come up with the answer.  The formula I presented above is from an old forum addressing this issue.  I made some changes to their formula and am now getting the results I need.  I'll post the new formula in case anyone is interested.  Thank you for your response.

            The Calculation Result is Text
            Let ( [ 
            theData=  militaryTime 
            ; theHour= Left ( theData ; 2 ) 
            ; theMinute= Right ( theData ; 5 )
            ; theMinuteResult= Left (theMinute ; 2 )
            ; theSeconds= "00"      
            
            ; theSuffix= Case ( theHour  ≥  12 ; "pm" ; "am" ) 
            ; theFInalHours = Mod ( theHour - 1 ; 12 ) + 1 
            ; theFinalMinutes= Right ( theMinuteResult ; 2 ) 
            
            ; result= theFinalHours & ":" & theFinalMinutes & " " & theSuffix 
            
            ]; 
            result
            )