phpmongodbdatemongodate

mongodb date not matching with the given value


While inserting data into mongodb collection I enter the date as '20-06-2015' and then convert it to mongo format using:

new MongoDate(strtotime(ClearContent(date("Y-m-d",strtotime($start_date)))));

But now when I check in database it shows this:

ISODate("2015-04-19T18:30:00.000Z")

Why does it take the date of yesterday.


Solution

  • Dates in mongodb are stored in UTC, and probably you are using a different timezone in PHP

    Try setting this at the beginning of your PHP script to use UTC timezone:

    date_default_timezone_set('UTC');