[BangPypers] date/time difference between two dates

Parthan SR parth.technofreak at gmail.com
Thu Feb 19 12:07:29 CET 2009


LOhit wrote:
> My question is, the date is in "Month day-of-the-month time" format in 
> the log file (ex. "Nov 22 15:15:42") and the current date I get from 
> "datetime" module is in ISO format. How do I convert the date in log 
> file to ISO format(or any other format) and then compare with the 
> current date/time.

 >>> import datetime   # or try `from datetime import datetime` and use 
`datetime.today()`

 >>> datetime.datetime.today()
datetime.datetime(2009, 2, 19, 16, 34, 40, 358989)

 >>> datetime.datetime.today().strftime("%d-%m-%Y")
'19-02-2009'

 >>> today=datetime.datetime.today().strftime("%d-%m-%Y")
 >>> today
'19-02-2009'

 >>> today_dtobj=datetime.datetime.strptime(today, "%d-%m-%Y")
 >>> today_dtobj
datetime.datetime(2009, 2, 19, 0, 0)

 >>> type(today_dtobj)
<type 'datetime.datetime'>

-- 
With Regards,

Parthan "technofreak" (2FF01026)
http://technofreak.in



More information about the BangPypers mailing list