How do you instantiate a datetime.timedelta
to a number of seconds in python? For example, 43880.6543
Edit (as per clarification by OP): I have an Excel sheet, where a cell shows 43880.6543 (when the format is Generic) instead of a date. How do I convert this value to a datetime
in python?
Just use
value = timedelta(seconds=43880.6543)
You can check the value is ok with
value.total_seconds()
Edit: If, in an Excel spreadsheet, you have a date expressed as a number, you can use python to convert that number into a datetime
by doing this:
value = datetime(1900, 1, 1) + timedelta(days=43880.6543)
# value will be February 2nd, 2020 in the afternoon
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With