ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

current date in rpg

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

  • current date in rpg

    how can i use current date in RPG program?
    can you give me any example ?

    i wanna do for example checking: if DATEFIELD <= current date

  • #2
    Re: current date in rpg

    ILE RPG it is %DATE()

    I oftentimes put in my program in my *INZSR routine or at the very beginning of my code.

    Code:
    Today = %Date();
    Then when I need to test against today's date it's just a matter of:

    Code:
    If DateField <= Today;

    Comment


    • #3
      Re: current date in rpg

      Great! thats what i needed

      Comment


      • #4
        Re: current date in rpg

        Originally posted by michal2442
        how can i use current date in RPG program?
        can you give me any example ?

        i wanna do for example checking: if DATEFIELD <= current date
        It actually depends on whether you want the system date or the job date.

        %Date() will give you the current _system_ date.

        The field UDATE contains the job date.

        The result of %Date will change if the program is active when the clock passes midnight - that may not be what you want. UDATE will remain fixed for the currency of the job and, in the case of web apps that is almost certainly not what you want!

        Comment


        • #5
          Re: current date in rpg

          I use a combination of %date() and the following definitions of job date and system date:

          * Job date
          D Jobdat s d inz(*job) datfmt(*iso)
          * System date
          D Sysdat s d inz(*sys) datfmt(*iso)

          Comment


          • #6
            Re: current date in rpg

            If you wish to use UDATE you can just change the example code to specify UDATE as an argument to %DATE.

            Code:
            Today = %Date(UDATE);

            Comment


            • #7
              Re: current date in rpg

              Originally posted by Rocky View Post
              If you wish to use UDATE you can just change the example code to specify UDATE as an argument to %DATE.

              Code:
              Today = %Date(UDATE);
              Correct - but we don't know for sure if he actually needs it in a date field - so he may just want to sue UDATE.

              Comment


              • #8
                Re: current date in rpg

                If you need the job date, and because the job date does not change, you may also just initialize your date variable with the job date:

                Code:
                D  JobDate       S                D      inz(*Job)
                   // or
                   DCL-S  JobDate Date Inz(*Job);
                Birgitta

                Comment


                • #9
                  Re: current date in rpg

                  ok, i need to use current system date, so %date(). In what format is it ? cause in my PF i have date in this format: 1140919 (for 19.09.2014). And i wanna compare for example %date() >= 1140919

                  Comment


                  • #10
                    Re: current date in rpg

                    You can control the format with the datfmt C spec, or the second parameter of the BIF.
                    the smoking gnu

                    Comment


                    • #11
                      Re: current date in rpg

                      It looks like you are you are using CYMD for you date format. If you try to specify that in the datfmt option you will get compile errors(or at least for me). Try the following.

                      Code:
                             dcl-s chardt char(10);
                      
                             chardt = %char(%date());
                             if %date(chardt:*cymd) >= FILE_FIELD;
                               // do stuff
                             endif;

                      Comment


                      • #12
                        Re: current date in rpg

                        I mean specify on the declaration or on the ctl-opt/h specs.

                        Code:
                               ctl-opt option(*srcstmt:*nodebugio) datfmt( *cymd );
                        RNF0617E Date format *JOBRUN, *CYMD, *CMDY, *CDMY or *LONGJUL is not allowed with DATFMT keyword.
                        Code:
                             d mydate          s               d   datfmt(*cymd)
                        RNF0617E Date format *JOBRUN, *CYMD, *CMDY, *CDMY or *LONGJUL is not allowed with DATFMT keyword.

                        Comment


                        • #13
                          Re: current date in rpg

                          %date always returns a date in *ISO format.

                          Comment


                          • #14
                            Re: current date in rpg

                            Originally posted by danlong005 View Post
                            It looks like you are you are using CYMD for you date format. If you try to specify that in the datfmt option you will get compile errors(or at least for me). Try the following.

                            Code:
                                   dcl-s chardt char(10);
                            
                                   chardt = %char(%date());
                                   if %date(chardt:*cymd) >= FILE_FIELD;
                                     // do stuff
                                   endif;
                            i cant use this code in free format : dcl-s chardt char(10);
                            i get message: An assignment operator is expected with the EVAL operation.

                            Comment


                            • #15
                              Re: current date in rpg

                              Change the chardt declaration to the following.

                              Code:
                                   d chardt          s             10a

                              Comment

                              Working...
                              X