Skip to content
Advertisement

Calculate the difference between two dates in javascript using react

I’m trying to get the difference between two date in react whith two datepicker and two timepicker ( a react component ). The date is for a booking and I want to get the duration by substract the “end date” with “start date”, but when I subtract two date whith more than 24 hours I have a -152 or a value that not corresponding to the real duration.

The code

JavaScript

The error

The code for the first DatePicker and the TimePicker ( for the start )

JavaScript

The code for the second dataPicker and TimePicker

JavaScript

Advertisement

Answer

Sample code using momentJS

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement