Georges Sery
Georges Sery

Reputation: 11

how to get the first day of the first month of the current year in RPGLE

dcl-s today date inz(*Sys) is the current sytem date How do i get the first day of the first month of the current year in this format 2017/01/01

Upvotes: 1

Views: 1568

Answers (2)

jmarkmurphy
jmarkmurphy

Reputation: 11473

Here's a slick trick:

   dcl-proc BuildDate;
     dcl-pi *n date;
       pyear     int(5) const;
       pmonth    int(5) const;
       pday      int(5) const;
     end-pi;

     dcl-ds *n;
       dateds   date(*iso) inz(d'0001-01-01');
       year     zoned(4:0) pos(1);
       month    zoned(2:0) pos(6);
       day      zoned(2:0) pos(9);
     end-ds;

     year = pyear;
     month = pmonth;
     day = pday;

     test(e) dateds;
     if %error;
       reset dateds;
     endif;

     return dateds;
   end-proc;

Now all you need to do to construct a valid date given Day Month and Year is:

FirstDOY = BuildDate(%subdt(%date(): *Y): 1: 1);

Upvotes: 1

Barry
Barry

Reputation: 448

You may want to look into the %SUBST built-in function.

date = d'1999-02-17';
time = t'01.23.45';
timestamp = z'1999-02-17-01.23.45.98765';

num = %subdt(date:*YEARS);
// num = 1999

num = %subdt(time:*MN);
// num = 23

Upvotes: 1

Related Questions