Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python)': 0.05; 'filesystem': 0.09; 'mtime': 0.09; 'output,': 0.09; 'looked': 0.10; 'modification': 0.15; 'appreciated!': 0.16; 'comparison.': 0.16; 'disk.': 0.16; 'doesnt': 0.16; "file's": 0.16; 'wrote:': 0.17; 'module,': 0.17; 'module': 0.19; 'all,': 0.21; 'import': 0.21; 'os,': 0.22; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'newer': 0.27; 'correct': 0.28; 'gary': 0.29; 'things,': 0.29; 'file': 0.32; 'to:addr:python- list': 0.33; 'entered': 0.34; 'list': 0.35; 'pm,': 0.35; 'something': 0.35; 'add': 0.36; 'compare': 0.36; 'turn': 0.36; 'subject:: ': 0.38; 'files': 0.38; 'received:10': 0.38; 'sure': 0.38; 'science': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'dr.': 0.72; 'institute': 0.72; 'received:204': 0.72; 'received:10.10': 0.75 Date: Mon, 29 Oct 2012 17:04:03 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: date and time comparison how to References: <50e576ea-2ebe-4340-954e-6c23b5885680@googlegroups.com> In-Reply-To: <50e576ea-2ebe-4340-954e-6c23b5885680@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351555829 news.xs4all.nl 6855 [2001:888:2000:d::a6]:46717 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32447 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