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

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

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 Denunciar

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 Denunciar

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 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