Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the number of days between two dates? [duplicate]

  1. I am calculating the number of days between the 'from' and 'to' date. For example, if the from date is 13/04/2010 and the to date is 15/04/2010 the result should be

  2. How do I get the result using JavaScript?

like image 564
udaya Avatar asked Apr 13 '10 06:04

udaya


People also ask

How do I extract the number of days between two dates?

To find the number of days between these two dates, you can enter “=B2-B1” (without the quotes into cell B3). Once you hit enter, Excel will automatically calculate the number of days between the two dates entered. Note that Excel recognizes leap years.

How do I calculate the number of working days between two dates in Excel?

The Excel NETWORKDAYS function calculates the number of working days between two dates. NETWORKDAYS automatically excludes weekends (Saturday and Sunday) and can optionally exclude a list of holidays supplied as dates.


1 Answers

const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds const firstDate = new Date(2008, 1, 12); const secondDate = new Date(2008, 1, 22);  const diffDays = Math.round(Math.abs((firstDate - secondDate) / oneDay)); 
like image 161
MaxVT Avatar answered Sep 29 '22 12:09

MaxVT