-3

Hi Guys i have two date firstDate = "06/11/2019" lastDate = "15/11/2019"

var date1 = new Date(firstDate);
var date2 = new Date(lastDate);
var diffTime = Math.abs(date2 - date1);
var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

i get diffDays=NaN. how can i do this. Thanks.

Mustafa
  • 63
  • 11

1 Answers1

0

Your lastDate is an invalid date. You can check this with

Date.parse("15/11/2019 00:00:00")

which will return a NaN

Check the Warnings section https://www.w3schools.com/js/js_date_formats.asp

Luca Filip
  • 61
  • 5
  • Date.parse is not work on lastDate still i get NaN. – Mustafa Nov 19 '19 at 08:31
  • Because your lastDate it is not a valid Date format. Your lastDate has the format: Day/Month/Year (DD/MM/YY) and it should be: Month/Day/Year (MM/DD/YY). My answer is about how to check if you have a valid date format which in your case it is not and that's why your result is NaN. lastDate should be: "11/15/2019 00:00:00" – Luca Filip Nov 19 '19 at 08:34