[Tutor] datetime.timedelta Output Format

Alan Gauld alan.gauld at btinternet.com
Mon Apr 2 09:39:36 CEST 2007


"R. Alan Monroe" <amonroe at columbus.rr.com> wrote

>> 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?

>>  >>> now = datetime.date.today()
>>  >>> print now
>> 2007-04-01
>>  >>> tis = now - tafmsd
>>  >>> print tis
>> 4785 days, 0:00:00

> 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.

I assume that what Will really means is how does he
get the number of days expressed as a number of
years/months and days.

As in: There are 4 months, 8 days to Xmas.

I don't use datetime so don't know whether/how that would be done
but it seems like a reasonable request.

And if that's not what Will wants can someone tell me
because I'm now curious! Its a non trivial conversion and
would require knowledge of the context - ie start or end date.

Alan G. 




More information about the Tutor mailing list