Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32449

Re: date and time comparison how to

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!newsfeed101.telia.com!starscream.dk.telia.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*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; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 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; 'received:192.168.1.3': 0.29; 'things,': 0.29; 'file': 0.32; 'could': 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; 'skip:o 20': 0.38; 'sure': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'reply- to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=MJviabll 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=xeM-YSbe-QNG9N15NwkA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Tue, 30 Oct 2012 00:50:48 +0000
From MRAB <python@mrabarnett.plus.com>
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>
In-Reply-To <508F1973.2030907@digipen.edu>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3061.1351558251.27098.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1351558251 news.xs4all.nl 6848 [2001:888:2000:d::a6]:34857
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32449

Show key headers only | View raw


On 2012-10-30 00:04, Gary Herron wrote:
> 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)
>
>
Instead of os.lstat(filename)[stat.ST_MTIME] you could use
os.path.getmtime(filename).

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 16:13 -0700
  Re: date and time comparison how to Gary Herron <gherron@digipen.edu> - 2012-10-29 17:04 -0700
  Re: date and time comparison how to MRAB <python@mrabarnett.plus.com> - 2012-10-30 00:50 +0000
    Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 18:47 -0700
      Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 19:02 -0700
        Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 19:13 -0700
          Re: date and time comparison how to Dave Angel <d@davea.name> - 2012-10-29 23:11 -0400
            Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 21:20 -0700
              Re: date and time comparison how to Chris Angelico <rosuav@gmail.com> - 2012-10-30 17:12 +1100
              Re: date and time comparison how to Dave Angel <d@davea.name> - 2012-10-30 05:35 -0400
            Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 21:20 -0700
          Re: date and time comparison how to MRAB <python@mrabarnett.plus.com> - 2012-10-30 03:30 +0000
        Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 19:13 -0700
      Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 19:02 -0700
    Re: date and time comparison how to noydb <jenn.duerr@gmail.com> - 2012-10-29 18:47 -0700
  RE: date and time comparison how to "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-31 21:04 +0000
  Re: date and time comparison how to Adam  Tauno Williams <awilliam@whitemice.org> - 2012-11-02 07:22 -0400

csiph-web