how to build a list of mx.DateTime objects from a start and enddate?

P

python

Hi-


I want to make a list of mx.DateTime objects that cover all the monthly
intervals between two points. For example:
[ ... a bunch of mx.DateTime objects including and between the startdate
and enddate ...]

How would I do something like this?


Thanks for the help.
 
C

Christos TZOTZIOY Georgiou

I want to make a list of mx.DateTime objects that cover all the monthly
intervals between two points. For example:
[ ... a bunch of mx.DateTime objects including and between the startdate
and enddate ...]

How would I do something like this?

I'm not familiar with the exact names of the mx functions, but what I
would do, would be:

create an empty list
set an mx.DateTime object to the start date
while the mx.DateTime is less or equal to the end date:
append it to the list, add one day to it

Add some parentheses and you got the python code :)
 
M

M.-A. Lemburg

Christos said:
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?


I'm not familiar with the exact names of the mx functions, but what I
would do, would be:

create an empty list
set an mx.DateTime object to the start date
while the mx.DateTime is less or equal to the end date:
append it to the list, add one day to it

Add some parentheses and you got the python code :)

Not the fastest, but the easy to read:

from mx.DateTime import Date, RelativeDate

def daterange(startdate, enddate, delta=RelativeDate(months=+1)):
l = []
date = startdate
while date < enddate:
l.append(date)
date += delta
return l

--
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source (#1, Sep 16 2003)________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
 
M

M.-A. Lemburg

Christos said:
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?


I'm not familiar with the exact names of the mx functions, but what I
would do, would be:

create an empty list
set an mx.DateTime object to the start date
while the mx.DateTime is less or equal to the end date:
append it to the list, add one day to it

Add some parentheses and you got the python code :)

Not the fastest, but the easy to read:

from mx.DateTime import Date, RelativeDate

def daterange(startdate, enddate, delta=RelativeDate(months=+1)):
l = []
date = startdate
while date < enddate:
l.append(date)
date += delta
return l

--
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source (#1, Sep 16 2003)________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top