Time zone of Mongo DB Installation

Is it possible to get “Time Zone” of the system on which the mongo db is installed? I understand Mongo DB stores dates in UTC. I wanted to know in which time zone is the server installed or system time zone and if that can be retrieved in Mongo DB Queries

Thanks

You can get an offset but that will work in time zone without day light saving. But, if you are in day light saving country, the offset cannot be used for a past date. So, I am still interested to know “which time zone” the mongo DB installation is on the system. Ideally if it can tell us Olsen Time Zone such as " America/New_York", it will be really great.

var now = new Date();
now.getTimezoneOffset()

I take back this comment. getTimezoneOffset gives me the client offset and not server offset.

What I really need is server offset or server time zone.

Hi @Vikram_Bade,

As far as I’m aware there’s no straightforward way to find the server timezone via a MongoDB query, but you could instead connect to the host environment (for example, using something like ssh user@hostname "cat /etc/timezone" on Linux).

However, since BSON dates are stored in UTC irrespective of the server timezone I’m curious if you can share more information on your intended use case.

In my own experience many admins use UTC for production servers to normalise times for cron jobs, log comparison, and diagnostics without having to deal with time offsets or daylight savings changes.

Regards,
Stennie

HI @Stennie_X,

Thanks for your response. In our team, we were discussing the need of storing “off set” of audit date columns.

For all functional columns, we are storing the offset as a field in Mongo DB Document.

We were thinking if we need to store the offset of audit columns (such as created date, updated date) as these dates are nothing but the time zone of the system (where mongo DB is installed). If I am able to get the time zone of the system, I do not need to worry about storing the offset and I can use the time zone to get my “local system time” (non UTC).

This is especially useful in multi time zone system which also has to deal with Day light savings. For example, if we need to write a query “Get me all documents which were updated on a day between this time and this time”, there the time will be given to me as “local time”, unless I know the offset or time zone, I cannot get data by just using UTC.

Hope this clarifies the use case.