Calculate days between two dates

We can find number of days between two dates in groovy by using the Date class. Creating an instance of today and yesterday we can determine the number of days separating by calling the date.minus() or using the - operator. In a comparable example we demonstrate how to find the difference between two dates in days using java.

Difference in days

@Test
public void difference_between_date_in_days() {

    def today = new Date()
    def yesterday = today - 1

    assert 1 == today.minus(yesterday)
    assert 1 == today - yesterday
}