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

87
Visualizações
Get beforeDate using dayjs

How do we get a date before the current date using DayJs.

I know how to get the current date but can we like remove 15 days from the current date?

cy.get('input[name="day"]').should('have.value', (Cypress.dayjs().format('DD')))
cy.get('input[name="month"]').should('have.value', (Cypress.dayjs().format('MM')))
 cy.get('input[name="year"]').should('have.value', (Cypress.dayjs().format('YY'))) ```


This is my code for getting the currentDate. I would like to get 15 days before my current Date. I would have used substract if the date was one input field but here we have different placeholders for the inputs.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

From the documentation:

dayjs().subtract(15, 'day');

Available units are mentioned here, day is one of them.

about 4 years ago · Juan Pablo Isaza Relatório

0

As @pavelsaman mentioned .subtract will work. Yo just have to format it to extract day, month, year.

const dayjs = require('dayjs')

cy.get('input[name="day"]').should(
  'have.value',
  dayjs().subtract(15, 'day').format('DD')
) //11
cy.get('input[name="month"]').should(
  'have.value',
  dayjs().subtract(15, 'day').format('MM')
) //10
cy.get('input[name="year"]').should(
  'have.value',
  dayjs().subtract(15, 'day').format('YY')
) //21
about 4 years ago · Juan Pablo Isaza Relatório

0

For readable test, calculate target once.

const target = dayjs().subtract(15, 'day')

cy.get('input[name="day"]').should('have.value', target.format('DD'))
cy.get('input[name="month"]').should('have.value', target.format('MM'))
cy.get('input[name="year"]').should('have.value', target .format('YY'))
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