date-time comparison, aware vs naive
noydb
jenn.duerr at gmail.com
Mon Dec 10 16:02:38 EST 2012
On Monday, December 10, 2012 3:52:55 PM UTC-5, Steven D'Aprano wrote:
> On Mon, 10 Dec 2012 11:57:37 -0800, noydb wrote:
>
>
>
> > I want to compare a user entered date-and-time against the date-and-time
>
> > of a pdf file. I posted on this (how to get a file's date-time) before,
>
> > was advised to do it like:
>
> >
>
> > import datetime, os, stat
>
> > mtime = os.lstat(filename)[stat.ST_MTIME] // the files modification
>
> > time
>
>
>
> What language are you writing? Using // for comments is not Python.
>
>
>
>
>
> > dt = datetime.datetime.fromtimestamp(mtime)
>
> >
>
> > I am having problems with the comparison, that line is failing.
>
>
>
> You haven't shown us the comparison line. Would you like us to guess what
>
> it does?
>
>
>
> My guess is that you are doing this:
>
>
>
> if mtime is dtime: ...
>
>
>
> Am I close?
>
>
>
> If not, please forgive me, my crystal ball is often faulty.
>
>
>
>
>
> > I think
>
> > I may have figured out the issue -- I think it is a matter of the file's
>
> > time being 'aware' and the user-input date-time being 'naive'.
>
>
>
> "Aware" of what?
>
>
>
>
>
>
>
> --
>
> Steven
Forgive me, I was just copying the code from the original reply to my orignal question.
Forgive me for not posting the comparison line, it goes something like
if one_time > another_time:
Forgive me - the 'aware' time vs 'naive' time refers to documentation I found for the datetime module, see second sentence down http://docs.python.org/2/library/datetime.html
More information about the Python-list
mailing list