ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Substract days from a Date.

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

  • Substract days from a Date.

    Hi All,

    I want to substract 7 days from a date in file. In file the date is in 3diff columns like,

    Year month Date
    2009 05 12
    2009 05 15
    2009 05 16

    now i think i cant use OPNQRYF(%DURDAY) as there are 3 fields, so i have to calculate the date in pgm.

    Pls suggest me how to do it in CLLE ?

    Thanks.

  • #2
    Re: Substract days from a Date.

    convert to julian then you can add subtract days and convert back.
    use the CVTDAT command to do this
    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


    • #3
      Re: Substract days from a Date.

      Try this.. As Jamii suggest
      I am giving you you simplest way to conver any date..

      the logic is if ur filter date is in *dmy ,*ymd or any other format just pass into the cl program and convert which way u want..

      Example of CL program WHICH TAKE PARAMETER AND COVERT

      Code:
      $TCU984C:    PGM        PARM(&DATE &DATE2 &FRFMT &TOFMT &ERROR)                      
                                                                                            
                     DCL        VAR(&DATE)   TYPE(*CHAR) LEN(8)                             
                     DCL        VAR(&DATE2)  TYPE(*CHAR) LEN(8)                             
                     DCL        VAR(&FRFMT)  TYPE(*CHAR) LEN(8)                             
                     DCL        VAR(&TOFMT)  TYPE(*CHAR) LEN(8)                             
                     DCL        VAR(&ERROR)  TYPE(*LGL)  LEN(1)                             
                                                                                            
        /*  Initialize Error Flag  */                                                       
                                                                                            
                            CHGVAR     VAR(&ERROR) VALUE('0')                               
                                                                                            
               /*  Set On Error Flag if Date is in Incorrect Format  */                     
                                                                                            
                    CVTDAT     DATE(&DATE) TOVAR(&DATE2) FROMFMT(&FRFMT) +                  
                                 TOFMT(&TOFMT) TOSEP(*NONE)                                 
                            MONMSG     MSGID(CPF0500) EXEC(CHGVAR VAR(&ERROR) +             
                                         VALUE('1'))                                        
      
      
      CALLING FROM RPG:
      C                   IF        #DATE  <> *ZEROS                  
       **  DATE CONVERSION                                            
      C                   EVAL      TEMPDAT=%CHAR(#DATE)              
      C                   CALL      'TCU984C'                         
      C                   PARM                    TEMPDAT             
      C                   PARM                    W@DAT10           8 
      C                   PARM      '*DMYY'       W@FMT9            8 
      C                   PARM      '*YYMD'       W@FMT10           8 
      C                   PARM                    W@EFLG            1 
      C                   MOVEL(P)  W@DAT10
      C                   IF        #DATE  <> *ZEROS                  
       **  DATE CONVERSION                                            
      C                   EVAL      TEMPDAT=%CHAR(#DATE)              
      C                   CALL      'TCU984C'                         
      C                   PARM                    TEMPDAT             
      C                   PARM                    W@DAT10           8 
      C                   PARM      '*DMYY'       W@FMT9            8 
      C                   PARM      '*YYMD'       W@FMT10           8 
      C                   PARM                    W@EFLG            1 
      C                   MOVEL(P)  W@DAT10       #FRMDATE1         8
      WHERE #FRMDATE1 IS COVERTED DATE IN *YYMD FORMAT...

      I THINK WTH THE HELP OF THIS CL AND rpg WE CAN SOVE ANY DATE ISSUE EASILY.nIO MORE THINK JUST PASS THE FORAMT TO CL AND COMPARE.....


      HOPE THIS WILL HELP


      Pramendra Pandeya
      Young people knows how to run fast but old people knows the way..

      Comment


      • #4
        Re: Substract days from a Date.

        Hi Jamief,

        Thanks for ur suggestion.
        manipulation of date is easy with julian date format. Only thing is I have to take care of subtraction for the date of begining of the year...

        Thanks.

        Comment


        • #5
          Re: Substract days from a Date.

          Hi Parsushi

          This is what I am currently doing with dates maybe this may help you. Currently I check if an employee has been terminated in the last 14 days so I minus 15 days from the current date and see if the date Terminated is greater. YADT = Date Terminated BTW it's in Julian so I convert it to Date. Hopefully this helps.

          Code:
          DAYS((DATE(CURRENT DATE)) -15 DAYS) < DAYS(DATE(DIGITS(DEC(F060116.YADT+1900000,7,0)))))

          Comment


          • #6
            Re: Substract days from a Date.

            Its even easier in RPG !

            Eval PrevDate = FileDate - %days(7)

            Why bother with CL ?

            Comment


            • #7
              Re: Substract days from a Date.

              In CL:
              Regards

              Kit
              http://www.ecofitonline.com
              DeskfIT - ChangefIT - XrefIT
              ___________________________________
              There are only 3 kinds of people -
              Those that can count and those that can't.

              Comment


              • #8
                Re: Substract days from a Date.

                Hello Kit!!

                I guess i posted above it is easiest way of use CVTDAT..just pass the required parameters and it will be converted in any foramt..

                Any thought to make above posted my code more efficient??


                Pramendra Pandeya
                Young people knows how to run fast but old people knows the way..

                Comment


                • #9
                  Re: Substract days from a Date.

                  Hi Pramendra

                  Just a little exercise

                  Using CL:
                  Take the date 2009-01-06 and calculate the date as at x days ago.
                  where x can be 7 or 512.
                  Please post the code here.
                  Regards

                  Kit
                  http://www.ecofitonline.com
                  DeskfIT - ChangefIT - XrefIT
                  ___________________________________
                  There are only 3 kinds of people -
                  Those that can count and those that can't.

                  Comment


                  • #10
                    Re: Substract days from a Date.

                    Originally posted by kitvb1 View Post
                    Just a little exercise

                    Using CL:
                    Take the date 2009-01-06 and calculate the date as at x days ago.
                    where x can be 7 or 512.
                    Please post the code here.
                    Yes Sir ...I actually hate Cl

                    but as it was your assignment so i did try and find this ...

                    Code:
                    [COLOR="Blue"]PGM PARM(&INDAYS)
                    
                        DCL VAR(&INDAYS)  TYPE(*DEC)  LEN(15 5)
                        DCL VAR(&DAYS)    TYPE(*DEC)  LEN(10)
                        DCL VAR(&LILIAN)  TYPE(*CHAR) LEN(4)
                        DCL VAR(&JUNK1)   TYPE(*CHAR) LEN(8)
                        DCL VAR(&JUNK2)   TYPE(*CHAR) LEN(23)
                        DCL VAR(&DATE)    TYPE(*CHAR) LEN(8)
                        DCL VAR(&CDAYS)   TYPE(*CHAR) LEN(10)
                    
                        /* Code to get today's date and add XXX number of days */
                    
                        CALLPRC PRC(CEELOCT) PARM(&LILIAN &JUNK1 &JUNK2 *OMIT)
                        CHGVAR VAR(%BIN(&LILIAN)) VALUE(%BIN(&LILIAN) + &INDAYS)
                        CALLPRC PRC(CEEDATE) PARM(&LILIAN 'YYYYMMDD' &DATE *OMIT)
                    
                        /* Code to display results */
                    
                        CHGVAR VAR(&DAYS) VALUE(&INDAYS)
                        CHGVAR VAR(&CDAYS) VALUE(&DAYS)
                        SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGTYPE(*COMP) +
                                  MSGDTA('In' *BCAT &CDAYS *BCAT 'days, the date +
                                  will be' *BCAT &DATE)
                    
                    ENDPGM[/COLOR]

                    Just pass the no of days to be added will giv you next date and you to get previous date pass as ...

                    Code:
                    [COLOR="Blue"]call adddays parm(-1)[/COLOR]

                    Pramendra Pandeya
                    Young people knows how to run fast but old people knows the way..

                    Comment


                    • #11
                      Re: Substract days from a Date.

                      Hi Pramendra,

                      That's about the same as the thread I already posted. I wanted you to see the difference between that and using a julian date for the calculations.

                      The thread poster did ask for CL after all.
                      Regards

                      Kit
                      http://www.ecofitonline.com
                      DeskfIT - ChangefIT - XrefIT
                      ___________________________________
                      There are only 3 kinds of people -
                      Those that can count and those that can't.

                      Comment


                      • #12
                        Re: Substract days from a Date.

                        Hello Kit,

                        I wanted to do it with julian date but it would hav been uncessary longer and require more mathmatics

                        This is guud lillian requires just 5 min and problem solved i.e days calculated

                        If u still want assigment to done with julian date i can give a try...

                        Pramendra Pandeya
                        Young people knows how to run fast but old people knows the way..

                        Comment


                        • #13
                          Re: Substract days from a Date.

                          For those who use the CEE-APIs and other procedures or programs that require integer/binary data type parameters:

                          Since Release V5R3 it is possible to directly define integer or unsigned integer variables within CL, so it is no longer necessary to use %BIN to convert a character string into an integer value.

                          PHP Code:
                              DCL VAR(&LILIAN)  TYPE(*INTLEN(4)

                              
                          CALLPRC PRC(CEELOCTPARM(&LILIAN &JUNK1 &JUNK2 *OMIT)
                              
                          CHGVAR VAR(&LILIANVALUE(&LILIAN + &INDAYS)
                              
                          CALLPRC PRC(CEEDATEPARM(&LILIAN 'YYYYMMDD' &DATE *OMIT
                          Birgitta

                          Comment


                          • #14
                            Re: Substract days from a Date.

                            Unluckily, my boss sees no advantage of upgrading our development/test box up from v5r2. Mainly for 2 reasons:
                            1. There are no improvements made to WRKQRY
                            2. He plays only on the live box (including running quick live data SQL or QRY fixes)
                            Regards

                            Kit
                            http://www.ecofitonline.com
                            DeskfIT - ChangefIT - XrefIT
                            ___________________________________
                            There are only 3 kinds of people -
                            Those that can count and those that can't.

                            Comment


                            • #15
                              Re: Substract days from a Date.

                              1. There are no improvements made to WRKQRY
                              ... Armes Kerlchen (poor boy) so you'll stay forever with Release V5R2, because Query/400 is "stabilized". All future database enhancements will be done for SQL (and Query/400 is NOT SQL).

                              ... I just showed my boss the enhancement in the SQL GROUP BY clause, i.e. CUBE, ROLLUP and GROUPING SET to built sums on each level your want. He seems to be convinced, we have to explain our clients they have to upgrade, so that we also can upgrade.

                              Birgitta

                              Comment

                              Working...
                              X