Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda