ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Converting 24hr format to 12 hr format with %EDITC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Converting 24hr format to 12 hr format with %EDITC

    I am trying to convert time in 24 hr format to 12 hr format

    I've used %EDITC thousands of times before but some reason this is causing me to have a brain fart

    I want to 1500 hrs to be converted to 3PM

    CHRS is packed (4,0)
    wkhrs is zoned(2,0)
    wkpmhrs is char(2)

    so it seems like
    wkhrs = CHRS / 100;
    wkpmhrs = %Editc((wkhrs - 12):'4') ;

    Would produce ' 3' when CHRS = 1500

    wkhrs = CHRS/100 = 15
    15-12 = 3
    wkpmhrs = %Editc((3):4') should be ' 3'


    I must be missing something because debug gives wkpmhrs = *blanks



  • #2
    Look at using %char() on your time value, you can specify the format to get the PM designation.

    Comment


    • #3
      Originally posted by Scott M View Post
      Look at using %char() on your time value, you can specify the format to get the PM designation.
      %CHAR will produce '3 ' (3 padded to the right with a blank. I need ' 3' (3 padded to the left with *blank

      Comment


      • #4
        There are lots of different ways to do this - but without knowing _exactly_ what you want the result to be it is difficult to recommend. Do you want b3:00pm or b300pm or ... if you wanted the former, then the RPG date routines could be a good choice. Just USATime = %Time($Char * 100); should do it.

        For the specific question you asked though you can simply use EVALR charTime = %Char( hours); That will right align the result instead of left aligning.

        Comment


        • #5
          Originally posted by JonBoy View Post
          There are lots of different ways to do this - but without knowing _exactly_ what you want the result to be it is difficult to recommend. Do you want b3:00pm or b300pm or ... if you wanted the former, then the RPG date routines could be a good choice. Just USATime = %Time($Char * 100); should do it.

          For the specific question you asked though you can simply use EVALR charTime = %Char( hours); That will right align the result instead of left aligning.
          If the given time is 1700 then I want to express it as b5:00, if it's 1630 then b4:30 (where b is a blank)



          Comment


          • #6
            OK - 'cos you had originally said "I want to 1500 hrs to be converted to 3PM" which implied you wanted the AM PM designation.

            Simple answer then (not fully tested)
            Code:
            dcl-ds  timeStuff;
                     timeUSA  time(*USA);
                     shortTime  char(5)  Overlay(timeUSA);
                   end-ds;
            
                   dcl-s inputTime  packed(4);
            
                   Dsply 'Enter time' ' ' inputTime;
            
                   DoU inputTime > 2400;
                      timeUSA = %Time( inputTime * 100 );
                      Dsply ('Short time is ' + shorttime );
                      Dsply 'Enter time' ' ' inputTime;
                   EndDo;
            
                   *InLr = *On;

            Comment


            • #7
              gratias

              Comment

              Working...
              X