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

167
Vistas
Date format in YYYY-MM-DD and DD should be current date-10days in Javascript

with this below code , I am getting what i need in this format YYYY-MM-DD, but I am trying DD should be -10 days from current date. in this example I am expecting to have 2022-04-04

var todayDate = new Date().toISOString().slice(0,10); 
console.log(todayDate)

Can someone please help in providing me working code. Thanks

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Try:

var tenDaysAgo = new Date(Date.now()- 1000 * 60 * 60 * 24 * 10)

console.log(tenDaysAgo.toISOString().slice(0, 10))

because there is 1,000 ms to a second, 60 seconds in a minute, etc.

about 4 years ago · Santiago Trujillo Denunciar

0

Slice is a js method which is used by an array (String is an array of char) and returns a shallow copy of the array selected from a start position to an end position.

According to the documentation

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.

For Example, "Hello, world".slice(0,5) is equal to "Hello".


If you want to get a date 10 days earlier, you can init the current date and then take of 10 days. This can be done whith the setDate and getDate methods

const date = new Date()
date.setDate(date.getDate() - 10)
console.log(date.toISOString().slice(0,10))

about 4 years ago · Santiago Trujillo 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