date and time comparison how to

noydb jenn.duerr at gmail.com
Tue Oct 30 00:20:44 EDT 2012


On Monday, October 29, 2012 11:11:55 PM UTC-4, 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?
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> 
> DaveA

okay, I see.
But for the user supplied date... I'm not sure of the format just yet... testing with a string for now (actual date-date might be possible, tbd later), so like '10292012213000' (oct 29, 2012 9:30pm).  How would you get that input into a format to compare with dt above?



More information about the Python-list mailing list