title: Java Date duration validation
body: <p>I will have 2 dates i.e. start date and end date. i have to calculate the duration between both the dates and then that duration should be checked for all below 3 conditions - </p>
  
  <ol>
  <li>If the duration is Equal to(1 year +- 5 days), then print "Hello".</li>
  <li>If the duration is Smaller than (1 year -5 days), then print "Hi".</li>
  <li>If the duration is Greater than (1 year + 5 days), then print "Hi". </li>
  </ol>
  
  <p>Please help me and let me know if any more information is required.</p>
  
  <p>I prefered to use joda time api. duration calculation is quite easy. I have problem to put the condition to validate with all above said 3 condition. whatever if condition i put in my program is not proper it seems. </p>
  
  <pre class="lang-java prettyprint-override"><code>import org.joda.time.DateTime;
  import org.joda.time.Period;
  
  class Test {
  
      public static void main(String[] args) {
          DateTime d1 = new DateTime(2011, 1, 1, 0, 0, 0, 0);
          DateTime d2 = new DateTime(2012, 1, 1, 0, 0, 0, 0);
          Period p1 = new Period(d1, d2);
          if (p1.getYears()==1 &amp;&amp; p1.getMonths()==0 &amp;&amp;
                  (p1.getDays()&lt;5||p1.getDays()&gt;5)) {
              System.out.println("Hello");
          } else {
              System.out.println("Hi");
          }
      }
  }
  </code></pre>
  
  <p>Thanks in Advance. </p>