Re: Difference between two dates in seconds

2006-09-28 Thread flupke
Duncan Booth schreef: > flupke <[EMAIL PROTECTED]> wrote: > >> Using 86400 instead of (24*60*60) is faster > > s/is/was/ > > upgrade to Python 2.5 Indeed, i'm still on 2.4. I thought 2.5 might give a different result :) Thanks for the info Benedict -- http://mail.python.org/mailman/listinfo/p

Re: Difference between two dates in seconds

2006-09-28 Thread Duncan Booth
flupke <[EMAIL PROTECTED]> wrote: > Using 86400 instead of (24*60*60) is faster s/is/was/ upgrade to Python 2.5 -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between two dates in seconds

2006-09-28 Thread flupke
Fredrik Lundh schreef: > def get_seconds(td): > ... return td.days * (24*60*60) + td.seconds > ... import dis dis.dis(get_seconds) > 2 0 LOAD_FAST0 (td) > 3 LOAD_ATTR0 (days) > 6 LOAD_CONST 4

Re: Difference between two dates in seconds

2006-09-27 Thread Fredrik Lundh
Steven D'Aprano wrote: > Arguably a better solution would be to do this: > > seconds = td.days * 24*60*60 + td.seconds if you're targeting an audience that cannot figure out what the expression does based on the names of the result and the names of the attributes, chances are that 24*60*60 won

Re: Difference between two dates in seconds

2006-09-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote: > On Wed, 27 Sep 2006 20:16:52 +0200, Fredrik Lundh wrote: > >> Claes at work wrote: >> >>> Please tell me there is a simpler way than subtracting two datetimes >>> to get a timedelta and then compute >>> >>> days * number of seconds per da

Re: Difference between two dates in seconds

2006-09-27 Thread Robert Kern
Steven D'Aprano wrote: > On Wed, 27 Sep 2006 20:16:52 +0200, Fredrik Lundh wrote: > >> Claes at work wrote: >> >>> Please tell me there is a simpler way than subtracting two datetimes >>> to get a timedelta and then compute >>> >>> days * number of seconds per day + seconds >>> >>> from it myself?

Re: Difference between two dates in seconds

2006-09-27 Thread Rob Williscroft
Steven D'Aprano wrote in news:[EMAIL PROTECTED] in comp.lang.python: > On Wed, 27 Sep 2006 20:16:52 +0200, Fredrik Lundh wrote: > >> Claes at work wrote: >> >>> Please tell me there is a simpler way than subtracting two datetimes >>> to get a timedelta and then compute >>> >>> days * number of

Re: Difference between two dates in seconds

2006-09-27 Thread Steven D'Aprano
On Wed, 27 Sep 2006 20:16:52 +0200, Fredrik Lundh wrote: > Claes at work wrote: > >> Please tell me there is a simpler way than subtracting two datetimes >> to get a timedelta and then compute >> >> days * number of seconds per day + seconds >> >> from it myself?? > > why would you have to do

Re: Difference between two dates in seconds

2006-09-27 Thread Claes at work
On 9/27/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Claes at work wrote: > > why would you have to do that yourself? why not let Python do it for > you? here's the code: > > seconds = td.days * 86400 + td.seconds > Thanks, but that is exactly what I meant. I had hoped there would some met

Re: Difference between two dates in seconds

2006-09-27 Thread skip
Claes> calculating the difference between two dates in seconds >>> import datetime >>> now1 = datetime.datetime.now() >>> # dum dee dum ... ... now2 = datetime.datetime.now() >>> now2-now1 datetime.timedelta(0, 12, 781540) Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference between two dates in seconds

2006-09-27 Thread Fredrik Lundh
Claes at work wrote: > Please tell me there is a simpler way than subtracting two datetimes > to get a timedelta and then compute > > days * number of seconds per day + seconds > > from it myself?? why would you have to do that yourself? why not let Python do it for you? here's the code:

Difference between two dates in seconds

2006-09-27 Thread Claes at work
Hi, I am learning Python and want to perform what I think is a very simple task: calculating the difference between two dates in seconds. Reading through the documentation I am puzzled: I can't find a way to do this without doing manually what I think belongs to a standard library m