How does one get a datetime
from a float
in Python?
For e.g, I have a float such as 43111.0 and I want to get the datetime
for this.
Looks like an Excel datetime format, called serial date. Quick and dirty way to convert it:
>>> import datetime >>> serial = 43111.0 >>> seconds = (serial - 25569) * 86400.0 >>> datetime.datetime.utcfromtimestamp(seconds) datetime.datetime(2018, 1, 11, 0, 0)
Try this:
from datetime import datetime datetime.fromtimestamp(*your_timestamp_here*).strftime('%Y-%m-%d')
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