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

155
Views
Mongo DB field convert to 12 hrs format from 24 hrs format

I need to convert and update date fields in 12 hrs format in one Collection(demo) through Mongo Db script.

Sample data is given below;

[
  {
    "_id": "dgdjh13233",
    "a": [
      {
        "b": [
          {
            "date": "03/26/2022 23.03 pm"
          },
          {
            "date": "03/26/2022 04.03 pm"
          }
        ]
      }
    ]
  },
  {
    "_id": "dgdjh132365",
    "a": [
      {
        "b": [
          {
            "date": "03/26/2022 22.03 pm"
          },
          {
            "date": "03/28/2022 08.03 pm"
          }
        ]
      }
    ]
  }
]

I need to update date fields for ex "date":"03/26/2022 22.03 pm" to "03/26/2022 10.03 pm". Is there any way to do this throgh scripts or can we find which all the data which are in 24 hrs format so that we can change it manually?

I am trying to fetch data throug scripts which are in 24 hours format but unable to do due to inadeqaute knowledge of mongodb.

db.getCollection("demo").find({},
{
"a.b.date":"$a.b.date",
"_id":NumberInt(0)
}
);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

"03/26/2022 23.03 pm" is a string, so if you want to convert from 12 to 24 hour in the mongod server, you will first need to convert that to a datetime with $dateFromString and then convert it back to a string in the format you want with $dateToString

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!