0

I am trying to calculate the number of days between two dates.

I have the number of days calculated in Chrome, Mozilla FireFox, and IE, but not in Safari. Safari says NaN. I have used Date.js and gave Date.parse but no luck.

Here is the code. I am trying to get number of days between 2 Dates.

angular.forEach($scope.tickets , 
  function(ticket) {
    ticket['noOfOpenDays'] = Math.floor(((new Date() - new Date(ticket.CreationDate))/(1000*60*60*24))) + 1;
    ticket['display'] = false;

    if(ticket.ActualCloseDate) {
        ticket['noOfDelivDays'] = Math.floor(((new Date(ticket.ActualCloseDate)-new Date(ticket.CreationDate))/(1000*60*60*24))) + 1;
    }
    else {
        ticket['noOfDelivDays'] = "N/A";
    }
});
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Ram
  • 9
  • 2
  • 1
    Do a `console.log(ticket.ActualCloseDate)` before the `if-else`. What's the value, or rather `console.log(ticket)` and does it have the property `ActualCloseDate`? – Spencer Wieczorek Sep 14 '15 at 22:43
  • 1
    Also `console.log(ticket.CreationDate);` And does the `NaN` occur when calculating `noOfDelivDays`, or `noOfOpenDays`? – Paul Roub Sep 14 '15 at 22:46
  • @SpencerWieczorek when i did a console.log i have some dates:2015-07-03 2015-06-16 2015-07-19, these dates are binding from database. – Ram Sep 15 '15 at 17:15
  • @PaulRoub NaN occurs for both the values noOfDelivDays & noOfOpenDays – Ram Sep 15 '15 at 17:18
  • Possible duplicate of [JavaScript: Which browsers support parsing of ISO-8601 Date String with Date.parse](http://stackoverflow.com/questions/5802461/javascript-which-browsers-support-parsing-of-iso-8601-date-string-with-date-par) – Paul Sweatte Feb 26 '16 at 12:14

0 Answers0