Shawn Milochik a écrit :
> I have done what I wanted, but I think there must be a much better way.
> 
> Given two timestamps in the following format, I just want to figure
> out how far apart they are (in days, seconds, whatever).
> 
> Format:
> 
> YYYY-MM-DD_MM:SS
> 
> Example:
> 2007-09-11_16:41
> 
> 
> It seems to me that to do what I want, I need to convert a string into
> a number (time.mktime()), such as this: 1189543487.0
> 
> Once I have that, I can just subtract one from the other and do
> whatever I want. The ugly part is converting something like
> 2007-09-11_16:41 to the numeric equivalent.
 >
> Below is my code. Any suggestions?

import time
print time.mktime(time.strptime("2007-09-11_16:41", '%Y-%m-%d_%H:%M'))
=> 1189521660.0

FWIW, you may also want to have a look at the datetime module, with 
special attention to the timedelta class.

HTH
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to