title: How to consider leap year when checking for date difference in SQL
body: <p>I have a situation, I save date in my database by splitting it into month,day,year while my base date is 2010-01-01.</p>
  
  <p>For example,</p>
  
  <p>Say my date is 2017-09-22 so this date will be saved in my database as below</p>
  
  <pre><code>basedate = 2010-01-01
  comparedate = 2017-09-22
  month = 92 //this is the number of month between the basedate and comparedate
  day = 2821//this is the number of days between my basedate and comparedate
  year = 7//this is the number of years between my basedate and comparedate
  </code></pre>
  
  <p>So say suppose I have to get those records which are from February irrespective of any year I am doing the below query which is working for me.</p>
  
  <pre><code>select * from XYZ where month - (year*12) = 1//1 for February.
  </code></pre>
  
  <p>When I am trying to get any records which is having date 12 irrespective of any month or year I am doing the below query.</p>
  
  <pre><code>select * from XYZ where day - (year*365) = 12//12 is my date.
  </code></pre>
  
  <p>Here I am facing the problem of leap year. My calculation goes wrong when the leap year is there in the records. </p>
  
  <p>Hope I am clear with my question.</p>