ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

date calculation

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

  • date calculation

    hi

    I need a utility/code to add number of days to a Date field and generate new Date. For e.g. if we add 6 days to 31-07-2006 it should give 6-08-2006. Please let me know if anything is available

    regards,
    sk

  • #2
    Re: date calculation

    sk1979,

    NewDate = OldDate + %DAYS( 6 );

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

    Comment


    • #3
      Re: date calculation

      Originally posted by MdnghtPgmr
      sk1979,

      NewDate = OldDate + %DAYS( 6 );

      HTH,
      MdnghtPgmr
      Just as a special note, NewDate will need to be a date type variable

      Comment


      • #4
        Re: date calculation

        As will OldDate...

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

        Comment


        • #5
          Re: date calculation

          thanks, it worked.
          Just want to know, is it possible RPGLE IV only?

          Comment


          • #6
            Re: date calculation

            Originally posted by sk1979
            thanks, it worked.
            Just want to know, is it possible RPGLE IV only?
            That is correct.

            Comment


            • #7
              date calculation in RPG

              in continuation of same thread, do we have sometjing in RPG?
              any pointers to piece of code?

              regards,
              sushrut

              Comment


              • #8
                Re: date calculation

                Date types did not exist prior to RPG-IV. Why would you want to not use RPG-IV?

                Comment


                • #9
                  Re: date calculation

                  We got round this problem with pre-RPG-IV by creating a diary file, which held a list of dates and day numbers, when we wanted to add/subtract dates we read the file with the YMD then +/- the difference and use the new YMD.

                  Comment


                  • #10
                    Re: date calculation

                    Someone is gonna kill me but you can use cvtdat (CL) convert to julian then add number of days to the julian date then convert back to whatever format you want.


                    jamie
                    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


                    • #11
                      Re: date calculation

                      Jamie ... isn't there something like multiplying by 10000.01 too? That's a dozy!
                      Your friends list is empty!

                      Comment


                      • #12
                        Re: date calculation

                        Yes there is Ill post it if I can find it...

                        dont tell anyone I posted it though K!

                        The 10000.01 trick only works because RPG compilers before ILE don't
                        care if you truncate numeric digits. I'd also question whether the RPGIII
                        community REALLY understands why this works.


                        PHP Code:
                        ~
                        0043.00      C                     MOVE PAYMDY    PAY20   20                    
                        0044.00      C                     MOVELPAYMDY    PAYMN   20                    
                        0045.00      C                     MOVE 40        PAYYR                         
                        0046.00       
                        /COPY C2SAMPLE/QRPGSRC,CUSTCPY                                    
                        0047.00      C           10239     COMP PAYDMY               94                 
                        0048.00      C                     MOVE UDATE     PAYMDY                        
                        0049.00      C           PAYMDY    MULT 10000.01  PAYYMD                        
                        0050.00      C           UYEAR     SUB  1         PAYYR                         
                        0051.00      C                     MOVE PAYYMD    DATE
                        ,
                        PHP Code:
                        ~
                        0047.00   CU C                     MOVE PAYMDY    PAY20   40                    
                        0048.00      C                     MOVELPAYMDY    PAYMN   20                    
                        0049.00   CU C                     MOVE 1940      PAYYR                         
                        0050.00   CUW 
                        /COPY QRPGSRC,CUSTCPY                                             
                        0051.00   CU C           01022039  COMP PAYDMY               94                 
                        0052.00   CU C                     MOVE 
                        *DATE     PAYMDY                        
                        0053.00   CU C           PAYMDY    MULT 10000.0001PAYYMD                        
                        0054.00   CU C           
                        *YEAR     SUB  1         PAYYR                         
                        0055.00      C                     MOVE PAYYMD    DATE
                        ,
                        jamie
                        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


                        • #13
                          Re: date calculation

                          Another way to calculate with dates in RPGIII is to use embedded SQL.
                          The following example shows what's neccessary to add a specified number of days to a numeric date.

                          PHP Code:
                          IDSDATA      DS                                         
                          I                                        1  10 DATEA    
                          I                                        1   20CENT     
                          I                                        1   40YEAR4    
                          I I            
                          '-'                       5   5 SEP1     
                          I                                        6   70MONTH    
                          I I            
                          '-'                       8   8 SEP2     
                          I                                        9  100DAY      
                           
                          *                                                      
                          IDSDATN      DS                                         
                          I                                        1   80DATEN    
                          I                                        1   40YEAR4N   
                          I                                        5   60MONTHN   
                          I                                        7   80DAYN     
                           
                          *-------------------------------------------------------
                          C/EXEC SQL SET OPTION DATFMT = *ISO                
                          C
                          /END-EXEC                                         
                          C                     Z
                          -ADD20060625  INDATE  80    
                          C                     Z
                          -ADDINDATE    DATEN         
                           
                          *                                                 
                          C                     Z-ADDYEAR4N    YEAR4         
                          C                     Z
                          -ADDMONTHN    MONTH         
                          C                     Z
                          -ADDDAYN      DAY           
                           
                          *                                                 
                          C           CENT      IFEQ *ZEROS                  
                          C           YEAR4     IFGE 40                      
                          C                     Z
                          -ADD19        CENT          
                          C                     
                          ELSE                         
                          C                     Z-ADD20        CENT          
                          C                     
                          ENDIF                        
                          C                     ENDIF                        
                           *                                                 
                          C                     Z-ADD10        NBRDAY  30    
                          C
                          /EXEC SQL                                                 
                          C
                          SET :DATEA CHAR(DATE(:DATEA) + :NBRDAY DAYSISO)     
                          C/END-EXEC                                                 
                           
                          *                                                         
                          C           DATEA     DSPLY                                
                          C                     Z
                          -ADDYEAR4     YEAR4N                
                          C                     Z
                          -ADDMONTH     MONTHN                
                          C                     Z
                          -ADDDAY       DAYN                  
                          C           DATEN     DSPLY                                
                           
                          *                                                         
                          C                     MOVE *ON       *INLR 
                          Birgitta

                          Comment


                          • #14
                            Re: date calculation

                            >>
                            C CENT IFEQ *ZEROS
                            C YEAR4 IFGE 40
                            C Z-ADD19 CENT
                            C ELSE
                            C Z-ADD20 CENT
                            C ENDIF
                            C ENDIF
                            <<
                            I believe this snippet is for when a 6 or 7 digit date is used.
                            â??No bird soars too high if he soars with his own wingsâ?? â?? William Blake

                            Comment

                            Working...
                            X