Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
it doesn't show remaining dates between start and end date , instead it has show only some other values..??? why, what's wrong with this..???
JavaScript
try {
    if ((start != null && start != "") && (end != null && end != "")) {
    // if (start<end){

        //var timeStart =new Date(parseInt(start));
        var timeStart = new Date(Date.parse(start));
        var start = timeStart.getUTCDate();
        console.log(start);
         //var twoDigitMonth = start.getMonth()+"";if(twoDigitMonth.length==1)  twoDigitMonth="0" +twoDigitMonth;

        var timeEnd =new Date(Date.parse(end));
        var end = timeEnd.getUTCDate();
         console.log(end);
         // timeStart=start-end;
        var hour = end-start  ;
        console.log(hour);
        return Math.floor(( start - end));


    } else {
        return "-";
    }
} catch (e) {
    return "-";
}
};

});



[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v2

1 solution

In what units do you want the difference?
The code you have here computes the differences between the day in month of two dates...
For instance the difference between the 11/02/2014 and the 14/05/2015 will be 3...
What you may want is the actual difference, which is 1 year 4 months and 3 days...
What you have is to compute the difference in the smallest unit we have in data object - milliseconds...You are lucky as simple subtraction will do it for you...
JavaScript
var v1 = new Date('February 11, 2014');
var v2 = new Date('May 14, 2015');

var d = v2 - v1;

Now d has the value of 39481200000, which is the difference between the two dates in milliseconds...
To convert it to a date you can use this:
JavaScript
var date = new Date(d);

Now the only problem is that data is a point-in-time vale where you need difference between two points...The solution is to know what the base for that point-in-time - it is 1st of January 1970...
So you can see the difference as year-month-day using this code:
JavaScript
date.getFullYear() - 1970);
date.getMonth() + 1);
date.getDate());

for a working demo see here: http://jsfiddle.net/nbjeqmo5/[^]
 
Share this answer
 
Comments
Member 11661764 1-Jun-15 8:00am    
kornfeld Eliyahu peter, sir , thanks for your kind response, now its working fine as i expect. i made it myself...!!!! now i got a other problem with uploading files module in angularjs..

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