parsing a date string

MikeyG mikewantsnospam at mephwantsnospam.net
Sun Mar 6 20:35:23 CET 2005


Hi,

I have a date string in the ctime() format ('Sat Mar  5 10:38:07 2005') 
and I want to know how long ago that was in whole days.

So far I have:

import time
import datetime
age = 
(datetime.date.fromtimestamp(time.mktime(time.strptime(date.strip()))) - 
datetime.date.today()).days

Which is an absurd number of function calls and is possibly not even 
correct (something in the docs about mktime() taking localtime whereas 
my string is in UTC)

Any suggestions?

Thanks
MikeG



More information about the Python-list mailing list