date and time comparison how to
Gary Herron
gherron at digipen.edu
Mon Oct 29 20:04:03 EDT 2012
On 10/29/2012 04:13 PM, noydb wrote:
> All,
>
> I need help with a date and time comparison.
>
> Say a user enters a date-n-time and a file on disk. I want to compare the date and time of the file to the entered date-n-time; if the file is newer than the entered date-n-time, add the file to a list to process.
>
> How best to do? I have looked at the datetime module, tried a few things, no luck.
>
> Is os.stat a part of it? Tried, not sure of the output, the st_mtime/st_ctime doesnt jive with the file's correct date and time. ??
>
> Any help would be appreciated!
Use the datetime module (distributed with Python) to compare date/times.
You can turn a filesystem time into a datetime with something like the
following:
import datetime, os, stat
mtime = os.lstat(filename)[stat.ST_MTIME] // the
files modification time
dt = datetime.datetime.fromtimestamp(mtime)
--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418
More information about the Python-list
mailing list