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

362
Views
convert mongodb creation date to utc +5 for a search filter, by date

Good morning and thanks in advance. I tell you my problem, I am making a filter to search for requests for certain specific elements and when searching for a date in YYY-MMM-DD I had the problem. It turns out that mongo saved it to me with this format:

createdAt 2022-07-10T18:11:28.630+00:00,

updatedAt 2022-07-10T18:11:28.630+00:00

which I was able to "fix" with:

if (payload.date) {
query.createdAt = { 
$gte: new Date(`${payload.date}T00:00:00.000-00:00`), 
$lt: new Date(`${payload.date}T23:59:59.999-00:00`) 
};

but my problem arose that when saving and searching by date, it seems that I save it with timezone zero, so I consult the date 2022-07-11 and it did not bring any data, I tried with 2022-07-12 and it just returned a response of documents.

I think my solution would be to use moment and convert it to utc +5 when doing the query. Does anyone have an idea how I can do that fix? I would appreciate it very much.

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

0

Maybe similar to this

query.createdAt = { 
   $gte: moment.tz(payload.date, "America/Toronto").startOf('day').toDate(), 
   $lte: moment.tz(payload.date, "America/Toronto").endOf('day').toDate()
};
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!