Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I Want like these

1st Date=31-Aug-2014(dd-MMM-yyyy)

2nd Date=28-Aug-2014(dd-MMM-yyyy)

DayDiff= (2nd Date - 1st Date)

Ans = 3
Posted

Try use this

JavaScript
var date1 = new Date("31/08/2014");
var date2 = new Date("28/08/2014");
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
alert(diffDays)​;
 
Share this answer
 
v2
 
Share this answer
 
First get Days from Your Dates and then take difference of that.
JavaScript
var SecondDate = new Date(31-Aug-2014);
var FirstDate = new Date(28-Aug-2014);
var SecondDateDay = SecondDate.getDay();
var FirstDateDay = FirstDate.getDay();
var DayDif = SecondDateDay - FirstDateDay
alert(DayDif);
 
Share this answer
 
Comments
Richard Deeming 28-Aug-14 16:08pm    
How many days are there between 30th August and 30th September? Your solution claims "0".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900