Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!