I have two dates which are generally the start_time and end_time. I want to take the difference between the times and round up the hours component if the minutes component is > 10 minutes. For example:
So here is the code what I am able to achieve until now. I am finding the difference between the two dates and diving it by 3600000 and rounding it up but that is something like converting 1 hour 30 minutes to 2 hours.
var duration = Math.round(moment(end_time).diff(moment(booking_result.start_time)) / 3600000);
Can anyone suggest a solution?
As I see you're using momenjs then it's easy what you want to do:
var duration = moment.duration(end_time.diff(start_time));
var hours = duration.asHours();
that will give you the duration in hours with decimals, as I understand from your question you want to do is round this upwards to the nearest integer, but only when this difference has more than 10 min. in the minutes component so:
if (duration.minutes() > 10) {
var result = Math.ceil(hours);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With