Fw: Re: how to build a list of mx.DateTime objects from a start and end date?

python python at sarcastic-horse.com
Tue Sep 16 18:57:13 EDT 2003


I wrote a generator to do it like so:

def dr(startdate, enddate):
	mm = mx.DateTime.RelativeDateTime(months=1)
	while startdate <= enddate:
		yield startdate
		startdate += mm


I created the list with:

>>>> import mx.DateTime
>>>> nov1999 = mx.DateTime.Date(1999, 11)
>>>> mar2003 = mx.DateTime.Date(2003, 3)
>>>> alldates = [d for d in dr(nov1999, mar2003)]

This was my first generator!



> Hi-
>
>
> I want to make a list of mx.DateTime objects that cover all the monthly
> intervals between two points.  For example:
>
>>>> import mx.DateTime
>>>> nov1999 = mx.DateTime.Date(1999, 11)
>>>> mar2003 = mx.DateTime.Date(2003, 3)
>>>> alldates = mk_list(startdate=nov1999, enddate=mar2003)
>>>> alldates
> [ ... a bunch of mx.DateTime objects including and between the startdate
> and enddate ...]
>
> How would I do something like this?
>
>
> Thanks for the help.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list