title: Convert a number (of days) to days, months and years with jQuery
body: <p>I have a calculation function and part of this shows the number of days it will take to achieve a goal.</p>
  
  <p>Rather than just show the number of days I want to calculate this into days &amp; months or days, months and years depending on the number. I have an if statement for the splitting but can't seem to work out the maths to go from for example 132 days to x days x months... Any suggestions?</p>
  
  <pre><code>// GOAL
  var timeToGoal = Math.round(goal / costPerDay);         
  
  // if more than a year
  if ( timeToGoal &gt;= 365 ) {
      alert('days + months + years');
  
      // if more than a month but less than a year
  } else if ( timeToGoal &gt;= 30 &amp;&amp; timeToGoal &lt;=365 ) {
      alert('Days + months');
  } else {
      alert('days');
      $('#savings-goal span').text(timeToGoal+' days');
  }
  </code></pre>