Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda