Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone

You can use the function tz_localize to make a Timestamp or DateTimeIndex timezone aware, but how can you do the opposite: how can you convert a timezone aware Timestamp to a naive one, while …

A faster strptime?

I have code which reads vast numbers of dates in ‘YYYY-MM-DD’ format. Parsing all these dates, so that it can add one, two, or three days then write back in the same format is slowing things down …

Make Sqlalchemy Use Date In Filter Using Postgresql

I’m trying to perform the following query in Sqlalchemy. Select * from “Mytable” where Date(date_time_field) = “2011-08-16”; I have tried several methods. Some here on SO. But none seems “realistic” …

Python: how to compute date ranges from a list of dates?

I have a list of dates, for example: [‘2011-02-27’, ‘2011-02-28’, ‘2011-03-01’, ‘2011-04-12’, ‘2011-04-13’, ‘2011-06-08’] How do I find the contiguous date ranges contained within those dates? In …

Checking date against date range in Python

I have a date variable: 2011-01-15 and I would like to get a boolean back if said date is within 3 days from TODAY. Im not quite sure how to construct this in Python. Im only dealing with date, not datetime. My working example is a “grace period”. A user logs into my site and if the grace period is within 3 days of today, additional scripts, etc. are omitted for that user. I know you can do some fancy/complex things in Python’s date module(s) but Im not sure where to look. Answer In Python to check a range you

How do I get a value of datetime.today() in Python that is “timezone aware”?

I am trying to subtract one date value from the value of datetime.today() to calculate how long ago something was. But it complains: The value datetime.today() doesn’t seem to be “timezone aware”, while my other date value is. How do I get a value of datetime.today() that is timezone aware? Right now, it’s giving me the time in local time, which happens to be PST, i.e. UTC – 8 hours. Worst case, is there a way I can manually enter a timezone value into the datetime object returned by datetime.today() and set it to UTC-8? Of course, the ideal solution

Trying to mock datetime.date.today(), but not working

Can anyone tell me why this isn’t working? >>> import mock >>> @mock.patch(‘datetime.date.today’) … def today(cls): … return date(2010, 1, 1) … >>> from datetime …

Python Date Comparisons

I would like to find out if a particular python datetime object is older than X hours or minutes. I am trying to do something similar to: if (datetime.now() – self.timestamp) > 100 # Where 100 …