Fractional Hours from datetime?

W. eWatson wolftracks at invalid.com
Sun Jan 10 12:28:15 EST 2010


Maybe there's a more elegant way to do this. I want to express the 
result of datetime.datetime.now() in fractional hours.

Here's one way.

dt=datetime.datetime.now()
xtup = dt.timetuple()
h = xtup[3]+xtup[4]/60.0+xtup[5]/3600.00+xtup[6]/10**6
#  now is in fractions of an hour



More information about the Python-list mailing list