how to get the difference between dates in days

25 views
Skip to first unread message

Ravi Mangalagiri

unread,
May 10, 2024, 11:12:42 AMMay 10
to Kogito development mailing list
Hi I have 2 date and trying to understand how to get the difference between dates and return the number of days...

I get some "PT-72H" as response.... please find the attached example

Is there any documentation on working with dates?
working_with_dates.dmn

Luiz Motta

unread,
May 10, 2024, 3:44:53 PMMay 10
to kogito-de...@googlegroups.com
Hi Ravi,

The difference between dates is a "duration", but I'm not sure why the default is in hours instead of using days/months/years. The "-" sign is due to a negative duration, if you invert the subtraction it will disappear. The first example in the FEEL handbook illustrates this behavior [1]. To convert to days, you can wrap the subtraction around parenthesis and access the "days" property (e.g. (businessGivenDate - processDate).days). You can see the "days and time duration" properties on [2]. Now, it appears the autocomplete does not suggest the type properties, it looks like a bug! I've created an issue on the kie-issues repo [3].


--
You received this message because you are subscribed to the Google Groups "Kogito development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kogito-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kogito-development/da84c4ec-ec1c-429c-84a9-d0195fc83a91n%40googlegroups.com.

Ravi Mangalagiri

unread,
May 10, 2024, 5:33:38 PMMay 10
to kogito-de...@googlegroups.com
Thanks Luiz! I attached a few samples based on documentation. 

qq, I still want to understand when I subtract 2 dates, it returns 'PT-72H', is there a documentation to understand these return format.... -72H means 3 days, but what about PT... similarly where to read on other formats?

Thanks
Ravi



--
Ravi Mangalagiri
working_with_dates.dmn

Luiz Motta

unread,
May 13, 2024, 10:18:39 PMMay 13
to kogito-de...@googlegroups.com
When you subtract two dates it will return a "duration". The "Conversion function" section of the FEEL handbook [1] mentions what is a "duration":

> duration string: Follows the format of days and time duration and years and months duration defined in the XQuery 1.0 and XPath 2.0 Data Model [2], such as P1Y2M.

From this document, you can see the "duration" follows the ISO 8601 [3], which brings:
P -- is used as the time duration designator, preceding a data element representing a given duration of time.
Y -- follows the number of years in a time duration.
M -- follows the number of months or minutes in a time duration.
D -- follows the number of days in a time duration.
H -- follows the number of hours in a time duration.
S -- follows the number of seconds in a time duration.
T -- is used as time designator to indicate the start of the representation of the time of day in dateTime.
Z -- is used as time-zone designator, immediately (without a space) following a data element expressing the time of day in Coordinated Universal Time (UTC) in dateTime, time, date, gYearMonth, gMonthDay, gDay, gMonth, and gYear.

PT-72H, is a time duration of -72 hours.


Reply all
Reply to author
Forward
0 new messages