Reputation: 725
Hi I am really confused over this. Do mongodb store date in any specific timezone? I know it store the datetime in UTC.
I have a website that store the user's record in mongo database using method
new MongoDate() in PHP
My website runs in Oregon server and default timezone set on my website is "America/Chicago". I am using mongo database version 3.0.
I store user's login information with their login datetime in mongodb.
What if the user is using the website from different timezones like Denver, India, Anchorage, Whitehorse (USA), Vancouver, etc. How would I know at what datetime they enter and how many users access the website on specified day?
In which timezone user's login datetime will be stored in the database if user login into the website from different timezones?
I have to create a graph to show user's status of their login on my website. I also want users to see their login status on graph according to their timezone.
Do mongo database add date with respect to user's local timezone?
Or can we add date with user's timezone if user of the website are accessing the website from different part of the world?
I want to show user's data to them according to their timezone.
Can any one help?
Upvotes: 1
Views: 1144
Reputation: 4619
MongoDB does not store timezone info within the date objects, and treats them as UTC.
It is up to the application to handle the conversions if local-time representation is needed.
Two options that could work for you are:
Store the users timezone preference and resolve all timestamps according to it.
Along with any date field that you store, keep another field with the timezone offset. Each timestamp could then be resolved independently.
Upvotes: 2