Pull Last 3 Months

Paul Hankin paul.hankin at gmail.com
Wed Oct 17 23:32:29 CEST 2007


On Oct 17, 9:59 pm, Harlin Seritt <harlinser... at yahoo.com> wrote:
> Is there a module that can pull str values for say the last 3 months?
> Something like:
>
> print lastMonths(3)
>
> ['Sep', 'Aug', 'Jul']

You should take a look at the 'datetime' module.

You can get the current month:
datetime.datetime.now().month

And a list of all abbreviated month names:
[datetime.datetime(1900, i + 1, 1).strftime('%b') for i in range(12)]

>From there, it shouldn't be too tricky to construct the list of months
you want.

--
Paul Hankin




More information about the Python-list mailing list