JQuery DateTime - compare days
just wodnering if it's possible to compare the difference in days between two dates, I have done this in c# like so, but can it be done in JQuery?
TimeSpan span = DateTime.Now - LastDate;
if (span.Days > 3)
{
}
else
{
开发者_运维百科
}
Anyone have any ideas?
Cheers
Here's a javascript function to get the days between 2 dates in javascript, no need for jquery here;
function days_between(date1, date2) {
// The number of milliseconds in one day
var ONE_DAY = 1000 * 60 * 60 * 24
// Convert both dates to milliseconds
var date1_ms = date1.getTime()
var date2_ms = date2.getTime()
// Calculate the difference in milliseconds
var difference_ms = Math.abs(date1_ms - date2_ms)
// Convert back to days and return
return Math.round(difference_ms/ONE_DAY)
}
精彩评论