Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
I know there's a way of calculating the number of days between two dates in freeform, but I can't remember what it is. Can someone refresh my memory?
Never mind! Found it!! %DIFF()!! Thanks anyway! :-)
Chris, "kind of".
%DIFF is only for date-minus-date math.
days = %diff( more-recent-Date : older-date : *DAYS );
To add a number of days, years, months, etc. you can use the + operator along with wrapping the duration value in %DAYS(), %MONTHS(), or %YEARS().
newDate = %Date() + %days(30);
If you get the dates backwards, it still works, you just get a negative result.
Can also specify *MONTHS or *YEARS. Manual is poorly worded, "The result is rounded down, with any remainder discarded." Which means it's not rounded, it's truncated. The example is 1 hour 59 minutes becomes 1 hour, but also applies to months with leftover days and so on.
Short forms of the durations are *D, *M, *Y.
Shame we don't have some method of cascade resulting so we can extract the remainder. Because at the moment to get "x Days, y Hours, z Minutes", I need to extract each then subtract multiples of x from y, and multiples of y from z.