[Tutor] datetime.timedelta Output Format

R. Alan Monroe amonroe at columbus.rr.com
Mon Apr 2 02:52:07 CEST 2007


> Is there a way to have the output of "print tis" in the same format as 
> "print now" and "print tafmsd" in the code below?
> Thanks,
> Will


> savage:~ wallison$ python
> Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import datetime
>  >>> now = datetime.date.today()
>  >>> print now
> 2007-04-01
>  >>> tafmsd = datetime.date(1994, 2, 23)
>  >>> print tafmsd
> 1994-02-23
>  >>> tis = now - tafmsd
>  >>> print tis
> 4785 days, 0:00:00
>  >>>

That seems like a weird idea. Are you really sure you want the number
of days between start and end dates displayed itself as a date? What
date would that be?

That's kind of like asking how to say "128 shopping days left until
Christmas" in the format of "2007-04-01 shopping days left until
Christmas". It doesn't work, somehow.

Alan



More information about the Tutor mailing list