Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Take a look at the Joda Time <a href="http://joda-time.sourceforge.net/xref/index.html" rel="nofollow">source code</a>. The <code>daysBetween</code> method of <a href="http://joda-time.sourceforge.net/xref/org/joda/time/Days.html" rel="nofollow">Days</a> is defined as:</p> <pre><code>public static Days daysBetween(ReadableInstant start, ReadableInstant end) { int amount = BaseSingleFieldPeriod.between(start, end, DurationFieldType.days()); return Days.days(amount); } </code></pre> <p><code>BaseSingleFieldPeriod</code>, like Days, is not available in Joda Time 1.2 but, looking at its <a href="http://joda-time.sourceforge.net/xref/org/joda/time/base/BaseSingleFieldPeriod.html" rel="nofollow">source</a> classes available in 1.2 start to appear:</p> <pre><code>protected static int between(ReadableInstant start, ReadableInstant end, DurationFieldType field) { if (start == null || end == null) { throw new IllegalArgumentException("ReadableInstant objects must not be null"); } Chronology chrono = DateTimeUtils.getInstantChronology(start); int amount = field.getField(chrono).getDifference(end.getMillis(), start.getMillis()); return amount; } </code></pre> <p>All of those classes and methods are available in Joda Time 1.2 so computing days between two instances would be something like:</p> <pre><code>public static int daysBetween(ReadableInstant oldDate, ReadableInstant today) { Chronology chrono = DateTimeUtils.getInstantChronology(oldDate); int amount = DurationFieldType.days().getField(chrono).getDifference(today.getMillis(), oldDate.getMillis()); return amount; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload