[Tutor] datetime module problem

Kent Johnson kent37 at tds.net
Thu Apr 17 15:29:11 CEST 2008


Dick Moores wrote:

>> You could either create n with hours=minutes=0, or round the 
>> difference up to the next whole number of days.
> 
> I have no idea how to implement either of 
> your suggestions as to how to eliminate it. Could you please spell 
> them both out?

1.

In [17]: n=datetime.today()
In [18]: n=datetime(n.year, n.month, n.day)
In [19]: n
Out[19]: datetime.datetime(2008, 4, 17, 0, 0)

2.

In [20]: diff=y-n
In [21]: diff
Out[21]: datetime.timedelta(0, 57464, 721369)
In [22]: days = diff.days
In [23]: if diff.seconds or diff.microseconds:
    ....:     days += 1
    ....:
    ....:
In [24]: days
Out[24]: 1

Kent


More information about the Tutor mailing list