Date difference in Javascript (ignoring time of day) -


I am writing a device rental application where the client is charged for rental of equipment on a period basis. (In days), basically, (daily charge * number of days) = total fee.

For quick response to the client, I have been trying to use JavaScript to find the difference between two calendar dates. I searched around, but I have not found anything, which I see I am here. I have noticed that most of the solutions are of the form:

  functionDetiff 1 (startup, endadet) {return (end .gettime) - startDate.getTime ()) / 1000 * 60 * 60 * 24); }  

My problem is that during any of those two dates the device can be checked at at any time and can return . The code above is computing the 24-hour period between two dates, when I am really interested in the number of calendar days. For example, if someone checks the device on July 6 on July 6 and it was returned at 10 o'clock on July 7, the code above will be calculated that more than one 24 hours has passed, and will return . The desired result is 1, because the date of only one calendar has passed (i.e. 6th 7th).

The closest solution I found is this function:

  function dateDiff2 (startDate, endDate) {return endDate.getDate () - startDate.getDate (); }  

Which I really want, as long as two dates are in the same month, however, because meeting (only) gives on the day of the month (i.e. 1-31), this work Does not occur when the dates are for several months (eg 1 day from 31 July to 1 August, but the above calculations 1 - 31, or - 29).

On the backend, in PHP, I am using GregorianTood (), which works just fine (see example). I can not find the equivalent solution in javascript.

Anyone have any ideas?

If you want to hire your student's camera for example all day ...


Comments