Calculating timespan

marek.rocki at marek.rocki at
Sun Sep 28 11:32:42 CEST 2008

Erhard napisał(a):
> I've been looking at the date/time classes and I'm at a loss as to how
> to do this (probably too used to other platforms).
> I have two date/time values. One represents 'now' and the other the last
> modified time of a file on disk (from stat). I need to calculate the
> difference in time (i.e., a 'timespan') between the two so I can tell if
> the file has been modified in the past X minutes and do something to it.
> Thanks =)

You can subtract one datetime object from another:

from datetime import datetime, timedelta
span = -
if span < timedelta(minutes=37):
    # do something

More information about the Python-list mailing list