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

142
Views
Vuejs global filters two params

I want to find the number of days between two dates with vue js, but I could not do it somehow.

For example,

the start will always be today, and the end date will be the date from the database.

Accordingly, I want to show the user how many days are left. if today's date has not passed the end date

  • 10 days after...
  • if today's date has passed the end date
  • 10 days late.
  • or if the dates are equal, I want TODAY to be written.

component

<p>{{'05/10/2021', '30/11/2021' | remainingday }}</p>

app.js

Vue.filter('remainingday ', function (start,end) {
    return
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try like following snippet:

new Vue({
  el: '#demo',
  data(){
    return {
      start: new Date(),
      end: new Date()
    }
  },
  filters: {
    remainingday (start, endDate) {
      const end = new Date(endDate)
      if(start.toDateString() === end.toDateString()) {
        return 'TODAY'
      } 
      const difDays = Math.floor((start.getTime() - end.getTime()) / (1000 * 3600 * 24))
      return difDays > 0 
        ? `PAYMENT DELAYED FOR ${difDays} DAYS `
        : `${difDays * -1} DAYS LEFT`
    }
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <label>Chose end date</label>
  <input type="date" v-model="end" />
  <p>{{start, end | remainingday }}</p>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

I opine this code work

Vue.filter('remainingday', function (value,start,end) {
   return value.match(start)
})



<p>{{ '' | remainingday('05/10/202','30/11/2021') }}</p>
about 4 years ago · Juan Pablo Isaza Report
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!