Midrange News for the IBM i Community


Posted by: Chris Proctor
Programmer Analyst
Columbia Sports Company
Portland, OR
Freeform equivalent of SUBDUR
has no ratings.
Published: 08 Dec 2011
Revised: 23 Jan 2013 - 1707 days ago
Last viewed on: 25 Sep 2017 (5825 views) 

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.

Freeform equivalent of SUBDUR Published by: Chris Proctor on 08 Dec 2011 view comments(4)

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?

Gracias!

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: chrisp
Premium member *
Portland, OR
Comment on: Freeform equivalent of SUBDUR
Posted: 5 years 9 months 20 days 1 hours 55 minutes ago

Never mind! Found it!! %DIFF()!! Thanks anyway! :-)

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Freeform equivalent of SUBDUR
Posted: 5 years 9 months 20 days 7 minutes ago
Edited: Thu, 08 Dec, 2011 at 12:56:42 (2119 days ago)

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);
Posted by: DaleB
Premium member *
Reading, PA
Comment on: Freeform equivalent of SUBDUR
Posted: 5 years 9 months 19 days 5 hours 24 minutes ago

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.

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Freeform equivalent of SUBDUR
Posted: 5 years 9 months 19 days 5 hours 2 minutes ago

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.