Reputation: 621
I have two long dates value.
For Ex: 1433097000000 1434479400000
Here i have to find the days between these two by jquery
For Ex: 15/06/2015 - 22/06/2015 If it is more than 5 days, I want to get from is 15/06/2016, to is 19/06/2015.
It is based on long values
Upvotes: 1
Views: 46
Reputation: 172378
Try this:
var d1= new Date(1433097000000);
var d2= new Date(1434479400000);
var x = (((d2- d1) / (1000 * 60 * 60 * 24)));
if(x>5)
{
d1.setDate(d1.getDate() + 4);
alert(d1);
}
If you want to format the date in dd/mm/yyyy format you can try like this:
function formatdate(mydate) {
function pad(s) { return (s < 10) ? '0' + s : s; }
var d = new Date(mydate);
return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('/');
}
Upvotes: 1
Reputation: 337560
First you need to get your timestamps in to Date()
objects, which is simple using the constructor. Then you can use the below function to calculate the difference in days:
var date1 = new Date(1433097000000);
var date2 = new Date(1434479400000);
function daydiff(first, second) {
return (second - first) / (1000 * 60 * 60 * 24);
}
alert(daydiff(date1, date2));
Upvotes: 1