Comparisons between date as facebook by jquery
<p>How to compare the time/date between dates as how facebook does? Please see the attached image to understand my requirement.
Is there any solution using jquery?</p>

<p><img src="http://i.stack.imgur.com/hQz7j.jpg" alt="enter image description here"></p>

<p>I tried as following js code, but i not have output in it code. what do i do?</p>

<p><strong>DEMO:</strong> <a href="http://jsfiddle.net/U9NV8/" rel="nofollow">http://jsfiddle.net/U9NV8/</a></p>

<pre><code>function mydiff(date1,date2,interval) {
    var second=1000, minute=second*60, hour=minute*60, day=hour*24, week=day*7;
    date1 = new Date(date1);
    date2 = new Date(date2);
    var timediff = date2 - date1;
    if (isNaN(timediff)) return NaN;
    switch (interval) {
        case "years": return date2.getFullYear() - date1.getFullYear();
        case "months": return (
            ( date2.getFullYear() * 12 + date2.getMonth() )
            -
            ( date1.getFullYear() * 12 + date1.getMonth() )
        );
        case "weeks"  : return Math.floor(timediff / week);
        case "days"   : return Math.floor(timediff / day); 
        case "hours"  : return Math.floor(timediff / hour); 
        case "minutes": return Math.floor(timediff / minute);
        case "seconds": return Math.floor(timediff / second);
        default: return undefined;
    }
}
alert(mydiff('2010-01-25','2010-02-20',1))
</code></pre>
