Retrieve the Day of the Week in RPGLE

Retrieve the Day of the Week in RPGLE

The simplest way to retrieve the day corresponding to a given date (@date in the code below) is to use the %rem() and %diff() built-in functions. The result is a one-digit numeric (1: 0) corresponding to the day, where zero (0) = Monday:

dcl-s dowk packed(1: 0);                             
                                                    
dowk = %rem(%diff(@date: d'0001-01-01': *days): 7); 
select;                                             
  when dowk = 0;                                    
    return 'MON';                                   
  when dowk = 1;                                    
    return 'TUE';                                   
  when dowk = 2;                                    
    return 'WED';                                   
  when dowk = 3;                                    
    return 'THU';                                   
  when dowk = 4;                                    
    return 'FRI';                                   
  when dowk = 5;                                    
    return 'SAT';                                   
  when dowk = 6;                                    
    return 'SUN';                                   
endsl;

Leave a Reply

Your email address will not be published. Required fields are marked *