Difference between two times (working ugly code, needs polish)

Shawn Milochik Shawn at Milochik.com
Tue Sep 11 17:20:36 EDT 2007


On 9/11/07, Grant Edwards <grante at visi.com> wrote:
> On 2007-09-11, Shawn Milochik <Shawn at Milochik.com> wrote:
>
> > I have done what I wanted, but I think there must be a much better way.
>
> See the strptime() function in either the time or the datetime
> modules:
>
> http://docs.python.org/lib/module-time.html
> http://docs.python.org/lib/module-datetime.html
>


Grant:

Thanks, this works, and is much shorter. Any further improvements, anyone?

def isOld(lastUpdate, runTimeStamp):

   oneDay = 60 * 60 * 24

   lastUpdate = time.mktime(time.strptime(lastUpdate, "%Y-%m-%d_%H:%M"))
   runTimeStamp = time.mktime(time.strptime(runTimeStamp, "%Y-%m-%d_%H:%M"))

   return (runTimeStamp - lastUpdate) / oneDay



More information about the Python-list mailing list