'Trouble subtracting dates in JS
I'm running this code in my vue component from a datepicker which returns the dates as shown in my data below.
Everything is good, except for when I console.log the days variable it's 0 when it should definitely be a larger number
Am I converting it incorrectly?
var vm =
new Vue({
el: "#app",
data: {
date_test1:'2021-02-02',
date_test2:'2021-05-15'
},
methods: {
testDate(){
const diff_in_days = Math.abs(new Date(date_test1) - new Date(date_test2));
const days = Math.ceil(diff_in_days / (1000 * 60 * 60 * 24));
console.log(days);
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
