date-time comparison, aware vs naive

noydb jenn.duerr at gmail.com
Mon Dec 10 14:57:37 EST 2012


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 
dt = datetime.datetime.fromtimestamp(mtime) 

I am having problems with the comparison, that line is failing.  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'.  The user-input date-time has a parameter type of date (calender and time tool supplied to enter), but is it 'aware'?  The comparison is not working so I think that it is not aware.  I can successfully compare two pdf file times against one another.  So, is there a way to cast that user-input value (prints as 2/10/2012 3:19:57 PM) as an 'aware' date-time?  How?  And can anyone confirm that my findings are probably correct?

Thanks for any help.



More information about the Python-list mailing list