[omaha] dateutils library
Hubert Hickman
hubert.hickman at gmail.com
Fri Dec 7 21:01:00 CET 2012
I second dateutil. It is incredibly handy when you need to do complicated
date things.
Hubert Hickman
On Fri, Dec 7, 2012 at 1:51 PM, Mike Hostetler <mike at squarepegsystems.com>wrote:
> I was struggling with some date arithmetic -- I need to take a given date
> and return back the beginning and ending date of the quarter that given
> date is in. Sounds fun, right? Yeah, I didn't think so either.
>
> Someone pointed me to the dateutils library and, after getting my brain
> around it, it turned out to be fairly straightforward.
>
>
> from dateutil import rrule,relativedelta
>
> year = this_date.year
> quarters = rrule.rrule(rrule.MONTHLY,
> bymonth=(1,4,7,10),
> bysetpos=-1,
> dtstart=datetime.datetime(year,1,1),
> count=8)
>
> first_day = quarters.before(this_date)
> last_day =
> (quarters.after(this_date)-relativedelta.relativedelta(days=1)
>
> More info on dateutil here:
> http://labix.org/python-dateutil
>
> Anyone else ever use it?
>
>
> --
> Mike Hostetler
> SquarePeg Systems
> http://www.squarepegsystems.com
> _______________________________________________
> Omaha Python Users Group mailing list
> Omaha at python.org
> http://mail.python.org/mailman/listinfo/omaha
> http://www.OmahaPython.org
>
More information about the Omaha
mailing list