Search code examples
javadatejodatimeandroid-jodatime

How to include start date in Joda Time daysBetween?


Upon testing JODA time to get number of days that has been selected, it is excluding the start day.

    Date from = day1.getTime();
    Date to = day2.getTime();

    int daysBetween = Days.daysBetween(new DateTime(from), new DateTime(to)).getDays();

So if I select, December 14 - 16, it is only showing "2" as result instead of 3.

Is it safe to just "+1" the result or is there a right way to do this in JODA time?


Solution

  • Actually Days.daysBetween(-,-) method just subtracts the start day from the end day. If you want to get the total no of days including the start day then you must have to minus 1 from the start date.