Javascript Relative Time - Display difference in Years & Months
<p>Have been fighting this for too many days.  I am trying to display the difference of a date (x) and now as follows:</p>

<ol>
<li>If the diff is exactly a year or years - just display the year diff</li>
<li>If the diff is years and months (1 year, 5 months) display it like that</li>
<li>If the diff is months (no years), display the months diff</li>
<li>If it's days, display the days.</li>
</ol>

<p>Hope that's clear - I'm very tired.</p>

<p>Here is my code (the commented lines are what I can't get to work):</p>

<pre><code>function RelativeTime(x){
    var plural = '';

    var mins = 60, hour = mins * 60; day = hour * 24,
    week = day * 7, month = week * 4, year = day * 365;

if (x &gt;= year){ x = (x / year)|0; dformat="year"; }
//else
//if ((x &gt;= year)&amp;&amp; (x &gt;= month)) { x = (x / year), (x / month)|0 ; dformat="year" , "month"; }
else if (x &gt;= month) { x = (x / month)|0; dformat="month"; }
else if (x &gt;= day*4) { x = (x / day)|0; dformat="day"; }
else if (x &gt;= hour) { x = (x / hour)|0; dformat="hr"; }
else if (x &gt;= mins) { x = (x / mins)|0; dformat="min"; }
else { x |= 0; dformat="sec"; }
if (x &gt; 1) plural = 's';
if (x &lt; 0) x = 0;
return x + ' ' + dformat + plural;
}
</code></pre>
