Skip to content

Tag: datetime

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 i…

Most recent previous business day in Python

I need to subtract business days from the current date. I currently have some code which needs always to be running on the most recent business day. So that may be today if we’re Monday thru Friday, but if it’s Saturday or Sunday then I need to set it back to the Friday before the weekend. I curre…

User-friendly time format in Python?

Python: I need to show file modification times in the “1 day ago”, “two hours ago”, format. Is there something ready to do that? It should be in English. Answer The code was originally published on a blog post “Python Pretty Date function” (http://evaisse.com/post/93417709/…

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: This generates a type error. What is the proper way to do date time comparison in python? I already looked at WorkingWithTime which is close but not exactly what I want. I …