How to get first/last day of the previous month?

Diez B. Roggisch deets at
Tue Jan 20 15:55:22 CET 2009

Hussein B wrote:

> Hey,
> I'm creating a report that is supposed to harvest the data for the
> previous month.
> So I need a way to get the first day and the last day of the previous
> month.
> Would you please tell me how to do this?

First day: create a new date-object with the day==1.

Last day: create a date-object with month + 1 and day==1, and subtract a
timedelta with one day of it.


More information about the Python-list mailing list