Obviously I could create a Calendar
object with the date and use get(DAY)
on it, but knowing Groovy, I would guess there is an easier, quicker way I just don't know about?
Answer
(date1..date2).size() == 1 // true if two dates are on same calendar day
We can use compareTo() function from Date class to compare the two dates. compareTo() function returns: 0 if both dates are equal.
Quickly opened the Groovy In Action book and found the following sample that should help:
def today = new Date()
def yesterday = today-1
assert (yesterday..today).size() == 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With