date time arithmatic
Lexy Zhitenev
zhitenev at cs.vsu.ru
Sun Jan 5 08:05:36 EST 2003
> Put simply I would like to determine the number of
> days between now() and some date in the past.
>
> E.g. now() - someCall(2002,9,2,0,0) = 126 days
>
> This seems possible in 2.3 alpha, but not in 2.2 (readily).
>
> Looking for pointers please?
>
If the dates you operate on are in the Unix Epoch (1970 - 2038), you can use
"time.mktime" function.
>>> import time
>>> def now(d, m, y):
... return int(time.mktime(d, m, y, 0, 0, 0, 0, 0, 0) / 86400) #
86400 - number of seconds passed since 1970/1/1.
So if you want to count the number of days between to dates use "now(2003,
1, 5)-now(1982, 5, 23)"
Lexy zhitenev at cs.vsu.ru
More information about the Python-list
mailing list