datetime: How to get diff between 2 dates in month units?

python python at sarcastic-horse.com
Sat Sep 13 09:55:49 EDT 2003


On Fri, 12 Sep 2003 16:50:53 -0500
"Pettersen, Bjorn S" <BjornPettersen at fairisaac.com> wrote:

<snip>

> No, but I do have one question..: would diff.months be valid given d1
> and d2 above (which also contain a day part)?


I'm not certain I understand. I guess what I'm trying to say is that I
want a datetime object that has months as its smallest unit, just like
datetime.date has days as its smallest indivisible unit.


> If so, what would it be given the dates 3/1/2001 - 1/30/2001; i.e. is a
> month 1/12 of a year, or until the same day next month (with special
> rules for end-of-month)?

My data is monthly-frequency, so when I do 2001m3 - 2001m1, it would
return 2.


> If you answer no to the first question then your very close to a (year *
> 100 + month) representation...

I will probably end up using something like this.  But before I build
that, I wanted to check around if I wasn't missing a more obvious solution.

Also, after I've got monthly data objects, I'm going to need to be able
to do the same thing for quarterly data.

 
> -- bjorn
> (time series data is fun ;-)

Amen to that.  Especially when it comes to handling weird stuff like
leap years and holidays that can be in different months.







More information about the Python-list mailing list