Your code
date1=27/5/2012
Actually means 27 divided by 5 divided by 2012. It is equivalent to writing
date1 = 0.0026838966202783303
date1 will be a number, and this number does not have a getDate
method.
If you declared them as actual date objects instead
var date2 = new Date(2012, 3, 19); var date1 = new Date(2012, 4, 27);
Could you fulfill
var diff = date1 - date2;
This will give you the difference in milliseconds between the two dates.
Here you can calculate the number of days, for example:
var days = diff / 1000 / 60 / 60 / 24;
source share