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

374
Visualizações
Yup date validation, End date after start date

here's my code, i'm trying to force the two date fields always to be different, the end date must be at least 1 day after the start date.

const EditSchema = Yup.object().shape({

       StartDate: Yup.date()
      .transform(value => (isDate(value) ? undefined : value))
      .typeError('Enter a start date')
      .required('Enter a start date'),

       EndDate: Yup.date()
      .min(Yup.ref('StartDate'), 'End date must be after start date')
      .transform(value => (isDate(value) ? undefined : value))
      .typeError('Enter an end date')
      .required('Enter an end date')
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

After hours trying to figure out how to do it.

here's the code.

when you have a date picker and you select a date, it will be something like this "01/01/2021 00:00:00".

So if you need the end date to be at least 1 day after the start date, you've got to add 1 hour to the start date which will not let you put 2 equal dates.


   StartDate: Yup.date()
      .transform(value => (isDate(value) ? undefined : value))
      .typeError('Enter a date')
      .required('Enter a date')
      ),
      EndDate: Yup.date()
      .min(Yup.ref('StartDate'), 'End date must be after start date')
      .when('StartDate', (st, schema) => {
      
        if(st != null){
          st.setHours(st.getHours() + 1);
          return schema.min(st)

        //this else prevents your page from crashing if there's any other input
        
         }else
          return schema.min('1900-01-01')

      })
      .transform(value => (isDate(value) ? undefined : value))
      .typeError('Enter a date')
      .required('Enter a date')
  });
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