Is there a difference between using PHPs time() and using new MongoDate()?
I need to store created_at and updated_at dates for each documents in by mongoDB collection
so that I can query them by date (for example documents updated last week).
From what I can see time() and new MongoDate() produces the same result?
That's because time() is default for the MongoDate constructor, from the manual:
public MongoDate::__construct ([ int $sec = time() [, int $usec = 0 ]] )
You should use MongoDate objects to query MongoDB.
If you use the raw output of time(), you will store/query for an integer. When you use MongoDate, you will be using MongoDB's Date type which gives you some additional benefits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With