Blog Archive

RPGLE Day of the Week example

RPGLE Sample Code to get day of week for the Current Date or any given date


d Day_Of_Week     s              1p 0                                  
D My_date         S               D   inz(d'2011-03-15')               
D My_date2        S              8s 0 inz(20110415)                    
                                                                       
 /free                                                                 
    // *Mon = 0 ... Sun = 6                                            
    Day_Of_Week = %rem(%diff(%date():d'0001-01-01':*days):7);          
                                                                       
    Day_Of_Week = %rem(%diff(My_date:d'0001-01-01':*days):7);          
                                                                       
    Day_Of_Week = %rem(%diff(%date(My_date2):d'0001-01-01':*days):7); 
                                                                      

    SELECT;                                                            
          WHEN Day_Of_Week = 0;                                        
            dsply '*MON';                                              
          WHEN Day_Of_Week = 1;                                        
            dsply '*TUE';                                              
          WHEN Day_Of_Week = 2;                                        
            dsply '*WED';                                              
          WHEN Day_Of_Week = 3;                                        
            dsply '*THU';                                              
          WHEN Day_Of_Week = 4;                                        
            dsply '*FRI';                                              
          WHEN Day_Of_Week = 5;             
            dsply '*SAT';                   
          WHEN Day_Of_Week = 6;             
            dsply '*SUN';                   
          OTHER;                            
    ENDSL;                                  
                                            
 /end-free               

2 comments :