Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8847447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:11:32+00:00 2026-06-14T12:11:32+00:00

I want to store the current date generated from PHP into MongoDB collection as

  • 0

I want to store the current date generated from PHP into MongoDB collection as an ISO date formate.

ISODate("2012-11-02T08:40:12.569Z")

However I am not able to generate such Kind of date in php which will be stored in MongoDB as an ISODate format.

This is what I ve done.

 $d = new MongoDate(time());
 echo $d;

and it is outputting something like,

0.00000000 1353305590

which is not the format I need. How to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:11:34+00:00Added an answer on June 14, 2026 at 12:11 pm

    You could run the __toString function, or use the sec field

    __toString will return a timestamp in usecs, which you can pass to date() after separating the seconds from milliseconds – read here: https://www.php.net/manual/en/mongodate.tostring.php

    OR, I personally prefer to have mongodb return just the seconds, which can be plugged directly into date() – read here: http://php.net/manual/en/class.mongodate.php

    Also, if you’re generating a MongoDate() for right now, you don’t need to specify time();

    In order to return an isodate, you need to do this:

    echo date(DATE_ISO8601, (new MongoDate())->sec);
    

    …

    $exampleDate = new MongoDate();
    echo date(DATE_ISO8601, $exampleDate->sec);
    

    EDIT: To save your ISO date, you need to do the following:

    $mongoDateObject = new MongoDate(strtotime("2012-11-02T08:40:12.569Z"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to store the current date into the core data. The entity is
I want to store the current date & time which can be get by
I have a problem. I want to store current date+ time in my database.
I want to convert the date I fetched from the database, which is generated
I want to store the current data/time and the Button Id into some file.
I want to store a .NET object into Azure Blob Storage. Currently I serialize
I want to store a very long string in database using php. The size
I want to store some dates into MySQL but those dates are without years
I store times in MySQL sent from a PHP script as CURRENT_TIMESTAMP . This
I'm building a login application, and I want to store the date the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.