Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching datetime from float in Python

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.

like image 265
Pravin Avatar asked Jul 15 '11 11:07

Pravin


2 Answers

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) 
like image 91
tuomur Avatar answered Oct 04 '22 18:10

tuomur


Try this:

from datetime import datetime  datetime.fromtimestamp(*your_timestamp_here*).strftime('%Y-%m-%d') 
like image 28
Sagar Dawda Avatar answered Oct 04 '22 18:10

Sagar Dawda