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

334
Vistas
Maximum range of 60 days in Angular between two date inputs

I need in JavaScript or TypeScript for Angular that the entered start date is not greater than 60 days for the entered end date... the logic would be: "maximum range 60 days" between the two inputs (dateFrom to dateTo). Hello, I need JS or Angular TS so that the entered start date is not greater than 60 days for the entered end date... the logic would be: "maximum range 60 days" for the inputs.

datepicker(){
  var dateFrom = this.consultaForm.get('desdeCreacion').value;
  var dateTo = this.consultaForm.get('hastaCreacion').value;

  
  if(dateTo > (dateFrom < this.datePipe.transform(new Date(dateTo).getTime()-5100000000), 'yyyy-MM-dd')){
    alert('Rango máximo 60 dias');
    window.location.reload();}
  }
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Thank you! I adapted your answers and I solved it like this:

  // Rango máximo 60 dias (sweetalert2)
  var dateFrom60 = this.datePipe.transform(new Date(dateFrom).getTime()+5150000000,'yyyy-MM-dd');
  if(dateTo > dateFrom60){
    this.hasta.reset();
    Swal.fire({
      icon: 'error',
      title: 'Rango máximo 60 días'
    })
  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

You could create a utility function just to calculate the differences in two dates, like so:

// Assuming fromDate and toDate are Date objects
// Otherwise you could convert them to Dates and pass here
function dayDifference(fromDate, toDate) {
  return Math.floor((toDate - fromDate)/(1000 * 60 * 60 * 24)) // Convert milliseconds to days
}

And then use this in your validation logic, like so:

if(dayDifference(dateFrom, dateTo) <= 60) {
    alert('Rango máximo 60 dias');
    window.location.reload();}
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

I feel like there is a better solution but you can you the Date Object and manipulate the date.

datepicker(){
  var dateFrom = new Date(this.consultaForm.get('desdeCreacion').value);
  var dateTo = new Date(this.consultaForm.get('hastaCreacion').value);

  
  if(dateTo > new Date(dateFrom.setDate(dateFrom.getDate() + 60)) ){
    alert('Rango máximo 60 dias');
    window.location.reload();}
  }

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