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


Groups > comp.lang.python > #32533

RE: date and time comparison how to

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: date and time comparison how to
Date 2012-10-31 21:04 +0000
References <50e576ea-2ebe-4340-954e-6c23b5885680@googlegroups.com> <508F1973.2030907@digipen.edu>
Newsgroups comp.lang.python
Message-ID <mailman.3125.1351717511.27098.python-list@python.org> (permalink)

Show all headers | View raw


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)
> 

You could also write that as:

datetime.datetime.fromtimestamp( os.path.getmtime( path ) )


Ramit P


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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