Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'chime': 0.09; 'mtime': 0.09; 'skip:t 60': 0.09; 'subtract': 0.09; 'thread': 0.11; 'modification': 0.15; '10:13': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'string': 0.17; 'wrote:': 0.17; 'import': 0.21; 'os,': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'ago': 0.27; 'guess': 0.27; 'rest': 0.28; 'gary': 0.29; 'received:192.168.1.3': 0.29; 'way?': 0.29; '(and': 0.32; 'received:84': 0.32; 'dates': 0.33; 'anyone': 0.33; 'to:addr :python-list': 0.33; 'entered': 0.34; 'pm,': 0.35; 'there': 0.35; 'compare': 0.36; 'method': 0.36; "i'll": 0.36; 'two': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'day.': 0.63; 'hours': 0.66; 'header:Reply-To:1': 0.68; 'reply- to:no real name:2**0': 0.72; 'difference.': 0.84; 'lastly,': 0.84; 'reply-to:addr:python.org': 0.84; 'angel': 0.93; 'examine': 0.95 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=YaM/Fntf c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=b2nRVtXOy8EA:10 a=47j2fiFj9IAA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=ukLjh4p7cegA:10 a=3iGL3dmQgNB-GDjQ92QA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Tue, 30 Oct 2012 03:30:27 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20121010 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> <508F1973.2030907@digipen.edu> <6101355b-ae00-4482-96ee-ed60f5cb465f@googlegroups.com> <85ea1841-6849-4970-b08b-5c7bbb7bba14@googlegroups.com> <6f437b0f-1fe5-49c6-98e3-7be615d04858@googlegroups.com> <508F4561.9070606@davea.name> In-Reply-To: <508F4561.9070606@davea.name> 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 Reply-To: python-list@python.org 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351567835 news.xs4all.nl 6882 [2001:888:2000:d::a6]:33772 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32461 On 2012-10-30 03:11, Dave Angel wrote: > On 10/29/2012 10:13 PM, noydb wrote: >> I guess I get there eventually! >> This seems to work >> >> pdf_timeStamp = time.strftime("%m%d%y%H%M%S",time.localtime(os.path.getmtime(pdf))) >> intermediateTime = time.strptime(pdf_timeStamp, "%m%d%y%H%M%S") >> pdfFile_compareTime = time.mktime(intermediateTime) >> >> (and I'll do the same to the user entered date-n-time and then compare) >> >> >> Lastly, so can anyone chime in and tell me if this is a good method or not? Is there a better way? > > Please read the rest of the thread in particular the message 3 hours ago > from Gary Herron > > import datetime, os, stat > mtime = os.lstat(filename)[stat.ST_MTIME] // the files > modification time > dt = datetime.datetime.fromtimestamp(mtime) > > Now you can compare two datetimes simply by > if dt1 < dt2: > > Or you can subtract them, and examine the difference. > > What's the need for all that string conversion stuff? > +1 Incidentally, the best order for dates is year (4 digits - remember Y2K? :-)) then month then day.