Read time from excel sheet using xlrd, in time format and not in float

Excel stores times as fractions of a day. You can convert this to a Python time as follows:

from datetime import time

x = excel_time # a float
x = int(x * 24 * 3600) # convert to number of seconds
my_time = time(x//3600, (x%3600)//60, x%60) # hours, minutes, seconds

If you need more precision, you can get it by converting to milliseconds or microseconds and creating a time that way.


The xlrd library has a built-in, xldate_as_tuple() function for getting you most of the way there:

import xlrd
from datetime import time
wb=xlrd.open_workbook('datasheet.xls')

date_values = xlrd.xldate_as_tuple(cell_with_excel_time, wb.datemode)  

# date_values is now a tuple with the values: (year, month, day, hour, minute, seconds),
# so you just need to pass the last 3 to the time() function.
time_value = time(*date_values[3:])