ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

%diff between two dates.

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

  • %diff between two dates.

    As I am reading, it looks like I can use the %diff with two date fields of the same type and get the number of days between the two within RPG FREE.

    I have my system date defined as follows and want to look at the days difference to a 7 digit date from my physical file. I didredefine that date also I did defined the nodays as numeric.

    tdate = %dec(%Char(%Date(udate:*mdy):*cymd0):7:0);
    ffpdtx = %dec(%Char(%Date(ffpdt:*mdy):*cymd0):7:0);
    nodays = %diff(tdate:ffpdtX:*days);

    My complile error msgs are:
    *RNF0580 20 1 The first parameter for %DIFF is not valid.
    *RNF0581 20 1 The second parameter for %DIFF is not valid.


    I think I am making this too hard. Thanks for your help.

  • #2
    Re: %diff between two dates.

    Hi Keggert:

    I think the compiler is saying tdate and ffpdtx should be date fields:


    Code:
    D tdate           s               D   datfmt(*mdy)
    D ffpdtx           s               D   datfmt(*mdy)
    
    nodays = %diff(tdate:ffpdtX:*days);
    Best of Luck
    GLS
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

    Comment


    • #3
      Re: %diff between two dates.

      If "TDate" and "FFPdTx" are both date data types:

      TDate = %Date();
      NoDays = %Diff( TDate : FFPDTx : *Days );


      Your statements:
      tdate = %dec(%Char(%Date(udate:*mdy):*cymd0):7:0);
      ffpdtx = %dec(%Char(%Date(ffpdt:*mdy):*cymd0):7:0);
      Is turning the TDate/FFPDTx fields into %Dec fields, not DATE fields


      hth
      -Rick

      Comment


      • #4
        Re: %diff between two dates.

        Also, as long as both fields are true "date" types, it doesn't matter what format they are. One can be *mdy, the other can be *cymd - it doesn't care.

        So, in your case, this would work

        NoDays = %diff(%date():%Date(ffpdt:*mdy):*D)

        Comment


        • #5
          Re: %diff between two dates.

          heres a bit of ugle code cause thats all I can write
          use this to call
          call diff parm(X'1060901F' 0 ' ')


          PHP Code:
                *
                *--------------------------------------------------------
                *
                *  
          entry plist
                
          *
               
          d DIFF            pr
               d  DateOneIn                     7  0
               d  Days                          7  0
               d  bigoerror                     1

               d DIFF            pi
               d  DateOneIn                     7  0
               d  Days                          7  0
               d  bigoerror                     1
                
          *
                * 
          Variable Definition
                
          *
               
          d dateerror       s               n
               d Decimal7        s              7  0
               d Decimal8        s              8  0
               d Today           s               d
               d WorkIso         s               d
               d WorkUSA         s               d   datfmt
          (*USA)

                /
          Free

                  
          //--------------------------------------------------------
                  // MAIN PROGRAM
                  //--------------------------------------------------------


                     
          test(de) *cymd dateOneIn;
                       if %
          error;
                        
          dateerror = *on;
                        
          bigoerror 'Y';
                       endif;


                  
          // if here then both dates are valid

                     
          if dateerror = *off;

                      
          // put todays date into *ISO format

                      
          today = %date();

                      
          // convert the in date to *ISO it is assumed it is *CYMD

                      
          WorkIso = %Date(dateOneIn:*CYMD);

                      
          // convert the in date to *ISO it is assumed it is *CYMD (decimal)
                      // just for show ;)  Notice the *zeros after *ISO...

                      
          Decimal8 = %uns(%char(%Date(dateOneIn:*CYMD)  :*ISO0));


                     endif;

                        
          Days = %diff(today:WorkIso:*days);



                       *
          inlr = *on;

                  
          //--------------------------------------------------------
                  // *inzsr - one time run subroutine
                  //--------------------------------------------------------
                       
          begsr *inzsr;


                       
          endsr;
                /
          End-Free

          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


          • #6
            Re: %diff between two dates.

            >> // convert the in date to *ISO it is assumed it is *CYMD (decimal)
            >> // just for show Notice the *zeros after *ISO...

            >> Decimal8 = %uns(%char(%Date(dateOneIn:*CYMD) :*ISO0));


            The ISO0 is only needed because you are converting the numeric-to-date-to-char-to numeric

            An easier way is

            Decimal8 = %dec((%Date(dateOneIn:*CYMD):*ISO)

            Comment


            • #7
              Re: %diff between two dates.

              I find this kind of statement:

              Decimal8 = %uns(%char(%Date(dateOneIn:*CYMD) :*ISO0));

              too confusing to place in productive code. I prefer to break it down to several statements in order to understand it better.
              Bill
              "A good friend will bail you out of jail,
              A true friend would be sitting beside you saying,
              'Wow, that was fun.'"

              Comment


              • #8
                Re: %diff between two dates.

                Bottom line is... there are NUMEROUS solutions ...find what works for you and don't forget to tell Jamie how ugle(?) his code is!!

                Comment


                • #9
                  Re: %diff between two dates.

                  If u havent figuried it owt.....I kant spill varrie well.
                  thanks @ick oh I mean Rick!
                  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

                  Working...
                  X