2 Replies Latest reply: May 15, 2014 10:06 AM by Data Kruncher RSS

    format time in 24 hour format

    svandyk _

      I'm on Monarch 10.5.  I see a thread from 2002 for earlier versions of Monarch regarding converting to a 24-hour time format.  Are there any new functions to convert time in AM/PM format to 24-hour format?  I have time in the format hh:mm:ss AM or PM that I need to convert to 24 hour time hh:mm with seconds optional.  Thank you


      Thanks I think your suggestion will work.  I will give it a try.

        • format time in 24 hour format
          Grant Perkins

          An interesting question.


          The problem with dates and times are that there are so many different formats in use that whilst using the Windows Region defaults to display a date in local format is normally enough, sometimes we need something else.


          AFAIK Monarch does not offer a ready made function to do this BUT if you make one (or follow on of the posts where suggested solutions are offered) you can then make use of the calculated field as an OBJECT in other models or turn it into a User Defined Function for the same purpose. In either case it can be tuned, documented and utilised precisely to your own requirements.


          The only point to consider is that the displayed result will, most likely, need to be a CHARACTER field rather than a date/time field. The chances are that would not matter but remember that using that field for further date/time related calculations would require additional round trip conversions (or the use of the original field of course ....)


          If anyone already has a readily available function in their UDF armoury they might feel able to make it available here. Let's see what we get.






            • format time in 24 hour format
              Data Kruncher

              For a quick solution, build the field 24Hour (as Grant said, a Character field) with:



              Right("00"+Trim(Str(Second(MyTime))),2)[/code]The field 24HourNoSeconds would be just:


              Right("00"+Trim(Str(Minute(MyTime))),2)[/code]Ideal would be a user defined function in the format 24Hour(TimeField,SecondsFlag) such that 24Hour(MyTime,1) would return the time with seconds, and 24Hour(MyTime,0) would return the time without the seconds.


              I'd think that something like:



              If(SecondsFlag=1,":"Right("00"Trim(Str(Second(MyTime))),2),"")[/code]would work nicely.