I have a rather basic question.
the date time for an entry in a collection is saved as
"lastUpdated": ISODate("2011-12-07T02:46:51.101Z")
which is in GMT format. How do I query the entry so that the query output i get is in EST format?
is this possible in the query itself or do I have to manually subtract 5 hrs (ESt = -5.00 hrs)?
The query i used is;
db.Collection.find({Type: 'Reports', patId: 'JOHNSONGARY'},
{'lastUpdated': 1} )
EDIT:
I use python for querying and am using the returned timestamp as such;
str(mongo_documents['lastUpdated'].strftime('%Y-%m-%d %H:%M:%S'))
How do i deduct 5 hours in this command?
Check out the documentation –
datetimeobjects returned by pymongo always represent a time in UTC, just as dates stored in MongoDB are always stored as (that is, assumed to be in) UTCpymongo can convert your datetimes automatically to be time zone aware if you set the tz_info flag to True when creating your Connection. You can then use datetime.astimezone() method to convert to another time zone if you wish.
So for example you could use pytz for timezones or if you only need EST write your own:
Then you can do this: