Am I asking too much from datetime?

thehaas at binary.net thehaas at binary.net
Tue Jun 1 17:14:18 CEST 2004


Yermat <loic at fejoz.net> wrote:
> Of course it does not work !
> 0 is not a valid day...
> You should do something like:

Except that it *does* work in other languages . . . that was part of
my point.  Here's a sample from some working Java code:

// this works in January!
Calendar now = Calendar.getInstance();
Calendar lastmonth = Calendar.getInstance();
lastmonth.set(now.get(Calendar.YEAR),
              now.get(Calendar.MONTH)-1,
              now.get(Calendar.DATE));

>  >>> import datetime
>  >>> today = datetime.date.today()
>  >>> print today
> 2004-06-01
>  >>> oneDay = datetime.timedelta(days=1)
>  >>> print oneDay
> 1 day, 0:00:00
>  >>> print today-oneDay
> 2004-05-31

Got it.  Cool -- thanks.


-- 
Mike Hostetler          
thehaas at binary.net 
http://www.binary.net/thehaas 



More information about the Python-list mailing list