Comparing dates issue

1
Wanted to compare two date fields within an exclusive split: if $SupT/StartDate >= $Cluster/StartDate then true else false Unfortunately, when dates are equal false (instead of true) is returned. Obviously a DateTime/Time/Timestamp problem? May it possible to add or subtract time (maybe with a variable such as dateTime(0, 0, 1, 00, 00, 00) ? Or is there another solution?
asked
3 answers
2

There are multiple routs to get around this issue. One, and the most easy one, would be to parse the date to a string giving you just the date part. i.e. formatDate($SupT/StartDate, 'yyyyMMdd')>= formatDate($Cluster/StartDate, 'yyyyMMdd').

And on a side note if you are doing this in an exclusive split you don't need to use the if statement. using

$SupT/StartDate >= $Cluster/StartDate

Is enough because this already returns true or false.

Edit: and if you want to be able to calculate with those days you should cast those strings to an Integer.

answered
5

You said "Unfortunately, when dates are equal false (instead of true) is returned". I'm assuming this is because you want only to compare the date part (ignoring the time part) of the DateTime values? Because a Mendix DateTime value always contains a time part, you'll first want to "round" your DateTime to a "date" before doing the comparison, like this:

trimToDays($SupT/StartDate) >= trimToDays($Cluster/StartDate)

Note that while Pieter's suggestion will give you the correct answer in practice, you're actually performing a lexicographical comparison and not an arithmetic one. So theoretically there is the possibility it might give weird/unexpected results.

answered
0

You could use the TrimToDays to set the timestamp equal.

answered