Problem solve Get help with specific problems with your technologies, process and projects.

Useful date expressions in V5R3/Free RPG

These are some useful expressions for working with dates in V5R3/Free RPG. They could be used directly in code, or encapsulated within functions.

These are some useful expressions for working with dates in V5R3/Free RPG. They could be used directly in code, or encapsulated within functions.

 
tDate: any date value EndofMonth, StartofMonth, StartYear: dates DaysInMonth, DaysinLastMonth, DayofMonth, Week: numeric (2,0)
DayofYear: numeric (3,0)
DayofWeek: numeric (1,0)

---------------------------
StartofMonth=TDate-%days(%subdt(TDate:*d))+%days(1);
EndofMonth=StartOfMonth+%months(1)-%days(1);
DaysInMonth=%diff(EndofMonth:StartofMonth:*days)+1;
DayofMonth=%subdt(Tdate:*d);
DaysinLastMonth=%diff(StartofMonth-%days(1):EndofMonth-%months(1):*days)
+1;
StartYear=TDate-%days(%subdt(TDate:*d))-%months(%subdt(TDate:*m))+%month
s(1)+%days(2);
DayOfYear=%diff(TDate:StartYear:*d)+1;
Week=%int(DayofYear/7)+1;
DayofWeek=%abs(%rem(%diff(tDate:d'2001-12-16':*d):7));//0=Sunday 

You can substitute expressions for defined variables in any formula, instead of having an extra variable.

Dig Deeper on RPG iSeries programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close