Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!