Re: Why can't timedeltas be divided?



Maric Michaud wrote:
Le Jeudi 25 Mai 2006 00:07, Dan Bishop a écrit :

If I try to write something like:

num_weeks = time_diff / datetime.timedelta(days=7)

because it has no meaning,

Yes, it does.

what you want is :

num_weeks = time_diff.days / 7
or
num_weeks = (time_diff / 7).days

Uh, no. Besides the integer division problem in your first line, keep in mind
that the .days attribute does not give you the time interval measured in days.
It gives you the number of *whole* days in the interval. The first method will
be incorrect if time_diff is not an even multiple of 1 day. The latter will be
incorrect if time_diff is not an even multiple of 7 days.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

.



Relevant Pages

  • RE: Help with creating a Macro
    ... I was looking back over my original message and I ... If you are trying to compute units per hour then your formula is incorrect. ... I feel a macro would be the most accurate and efficient ... Most of the order data are on multiple rows. ...
    (microsoft.public.excel.misc)
  • Re: Table design help
    ... Multiple tables is incorrect. ... On FrmOutcome, disable comment. ... Put the following code in the AfterUpdate ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Executing exp as batch job fails
    ... You have multiple tnsnames.ora floating around, ... incorrect, you didn't set the TNS_ADMIN variable, and your DOS box is ... hitting the wrong one, as that one is the one in the %ORACLE_HOME% it ... out, is incorrect, the PATH in your interactive session can differ from ...
    (comp.databases.oracle.misc)
  • Re: Not using .cpp files when programming...
    ... >> Your compiles will be slower. ... >> .h in multiple programs that are linked together. ... that's incorrect: neither 'inline' nor 'static' is used ...
    (comp.programming)