ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

retrive Current time

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

  • retrive Current time

    It seems like this should be easier to find, but how do you retrieve the system time? Manuals keep directing me to %time and %timstamp, but it looks like those are for converting and not retrieving. Can anyone help me on this?

  • #2
    Re: retrive Current time

    CurTime = %TIME();

    HTH,
    MdnghtPgmr
    "Tis better to be thought a fool then to open one's mouth and remove all doubt." - Benjamin Franklin

    Comment


    • #3
      Re: retrive Current time

      time = %time()
      Code:
      cmdstring = 'sndmsg Msg(' +                
                   Q +                           
                  'The Time is ' +               
                   %char(%time()) +              
                   Q +                           
                  ')' +                          
                  ' tousr('  + %trim(workuser) + 
                  ')'
      timestamp = %timestamp()
      Code:
            *                                                                   
            *  Field Definitions.                                               
            *                                                                   
           d ISOdate         s               d                                  
           d ISOtime         s               t                                  
           d thestamp        s               z                                  
                                                                                
            *=============================================================      
            *  M A I N     L I N E                                              
            *=============================================================      
           c                   eval      thestamp = %timestamp()                
           c                   eval      ISODate = %date(thestamp)              
           c                   eval      ISOtime = %time(thestamp)              
           c                                                                    
                                                                                
                                                                                
           c                   eval      *inlr = *on

      Code:
            *                                                                        
            *  Field Definitions.                                                    
            *                                                                        
           d TimeX           s               T                                       
           d TimeDec         s              6  0                                     
            *=============================================================           
            *  M A I N     L I N E                                                   
            *=============================================================           
            *                                                                        
           c                   eval      Timex = %time()                             
           c                   eval      TimeDec = %uns(%char(%Time():*HMS0))        
            *                                                                        
           c                   eval      *inlr = *on                                 
            *

      Code:
          // calculate where we are in the day and put that in as a decimal 
                                                                            
              hour = %subdt(%time():*hours);                                
              select;                                                       
               when hour <= 8;                                              
                hour = 1;                                                   
               when hour <= 9;                                              
                hour = 2;                                                   
               when hour <= 10;                                             
                hour = 3;                                                   
               when hour <= 11;                                             
                hour = 4;                                                   
               when hour <= 12;                                             
                hour = 5;                                                   
               when hour <= 13;                                             
                hour = 6;                                                   
               when hour <= 14;                                             
                hour = 7;                                                   
               when hour <= 15;                                             
                  hour = 8;               
                 when hour <= 16;         
                  hour = 8;               
                 when hour <= 17;         
                  hour = 8;               
                endsl;                    
                                          
                 MTDDAYS +=  (hour/8);    
                                          
                 if MTDDAYS < 1;          
                  MTDDAYS = 1;            
                 endif;
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


      • #4
        Re: retrive Current time

        A couple of different methods:

        1) If you are running a report, can use the D-Specs. This method gives you the time when the program starts. Note that the Time Format can be several different types (*HMS, *ISO, *USA, *EUR, *JIS).
        Code:
        D XTime           S               T   TimFmt(*ISO) Inz(*Sys)
        2) Free form method:
        Code:
        /free
           XTime = %TIME();
        /end-free
        3) Fixed format method:
        Code:
              *                  OpCode                  Result Field
             C                   Time                    XTime
        Last edited by Chipper; January 9, 2009, 02:42 PM.
        http://www.linkedin.com/in/chippermiller

        Comment


        • #5
          Re: retrive Current time

          or if you like unnecessary pain you can use the QWCRSVAL API to get the value of QTIME system value
          I'm not anti-social, I just don't like people -Tommy Holden

          Comment


          • #6
            Re: retrive Current time

            I'm trying to move it to a numeric field that's 6 digits long. I've tried
            Code:
            fieldx=%TRIM();
            but the types are not the same. So, I tried
            Code:
            fieldx = %DEC(%TRIM():6:0);
            ...but then the second parameter for %DEC isn't valid.

            Comment


            • #7
              Re: retrive Current time

              Here's one way to do it:

              Code:
                         
              d fieldx          s              6s 0     
               /free                                    
                                                        
                  fieldx =  %dec( %time : *HMS ) ;           
                                                        
                  dsply %editc( fieldx : 'X' );          
                                                        
                  return;




              And a longer version:


              Code:
              d fieldx          s              6s 0                                
               /free                                                               
                  fieldx = %dec( %subdt( %time : *hours   ) : 2 : 0) *10000 +      
                           %dec( %subdt( %time : *minutes ) : 2 : 0) *100 +        
                           %dec( %subdt( %time : *seconds ) : 2 : 0)  ;            
                                                                                   
                  dsply %char( fieldx );                                           
                                                                                   
                  return;
              Last edited by MichaelCatalani; January 10, 2009, 12:23 AM.
              Michael Catalani
              IS Director, eCommerce & Web Development
              Acceptance Insurance Corporation
              www.AcceptanceInsurance.com
              www.ProvatoSys.com

              Comment


              • #8
                Re: retrive Current time

                VoilinSC,
                There is an EASY way. Use the TIME command and specifiy a 6-digit numeric field in result field and you are done ! No BIF's or conversion required.
                Code:
                     C                   TIME                    MyNumField

                Comment


                • #9
                  Re: retrive Current time

                  Arrow, I was informed on that approach, but I like to have my programs completely in free format. Michael's way works great.

                  Code:
                  fieldx =  %dec(%time : *HMS) ;
                  It makes perfect sense. I just didn't know that *HMS would bring in the complete time.

                  Comment

                  Working...
                  X