Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date function

Status
Not open for further replies.

thelearner

Programmer
Jan 10, 2004
153
US
Hi,

I have 2 fields, one contains month and the other contain year (each 2 char. long), which is my ending period. I want to find starting period(-11 months). I know if I have full date (cymd) then I can use fxn %month(-11). Can I subtract months from only the mm and yy portion that I have or do I have to have full date format.

Thanks.
 
I don't think you can use RPG BIFs on a portion of date. IMHO, the simplest way to subtract a duration from your date portion is to build a standard *ISO full date format as the following . Fields MyYear and MyMonth match your 2 char fields, yy for thousandth and dd for the first day of any month.

Code:
     D yyyymmdd        ds                                  
     D  yy                            2A   inz('20')       
     D  MyYear                        2A   inz('04')       
     D                                1A   inz('-')        
     D  MyMonth                       2A   inz('03')       
     D                                1A   inz('-')        
     D  dd                            2A   inz('01')       
                                                           
     D MyDate          s               D                   
     D Less11Month     s               D                   
                                                           
     C                   Move      yyyymmdd      MyDate    
      /free                                                
                 Less11Month = MyDate - %MONTHS(11);     
                 dsply Less11Month;                      
                 return; 
      /end-free;

HTH -- Philippe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top