Search code examples
python-datetime

convert(float,getdate()) sql to time in python


I am parsing a .csv file in python. The file is saved from a different program, which uses sql to save a date column as convert(float,getdate())+2 in a column called 'lastupdated'. It looks like this:

enter image description here

If I change the format to 'Time' in the .csv file, it looks like this:

enter image description here

Is there a way to do this in Python? I've tried a few codes, but nothing has worked yet.

datetime.strptime('43881.45608','%H:%M:%S') pd.to_datetime(43881.45608,unit='h')

enter image description here

I either get an error or an incorrect value like in the above example. Could anyone please guide me in the right direction? I'm relatively new to Python.

Thank you.


Solution

  • import xlrd
    df['lastupdated'].apply(lambda d: datetime(*xlrd.xldate_as_tuple(d, 0)).strftime("%H:%M:%S"))