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

121
Views
get epoch time in js using new date for 7 days back midnight in javascript?

I am trying to get 7 days back epoch 12 am time but I am getting 7 days back time but same as the time at present like at 5 pm it gives 7 days back but at 5pm istead of 12 am. below code is what I tried:

  let createdAt = new Date();
 createdAt = new Date().setDate(createdAt.getDate()-7);

please help me to understand , how to get 12 am of 7 days back?, thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to zero the time too, e.g.

let createdAt = new Date();
createdAt.setHours(0,0,0,0);
createdAt = new Date().setDate(createdAt.getDate()-7);

The last line could also be:

createdAt = createdAt.setDate(createdAt.getDate() - 7);

since the set methods return the time value of the updated date.

Or create a new Date from just the date parts and get its time value, e.g.

let d = new Date();
let ms = new Date(d.getFullYear(), d.getMonth(), d.getDate() - 7).getTime();

console.log(ms + '\n' + new Date(ms).toString());

about 4 years ago · Juan Pablo Isaza 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!