How can one convert a serial date number, representing the number of days since epoch (1970), to the corresponding date string? I have seen multiple posts showing how to go from string to date number, but I haven't been able to find any posts on how to do the reverse.
For example, 15951
corresponds to "2013-09-02"
.
>>> import datetime
>>> (datetime.datetime(2013, 9, 2) - datetime.datetime(1970,1,1)).days + 1
15951
(The + 1
because whatever generated these date numbers followed the convention that Jan 1, 1970 = 1.)
TL;DR: Looking for something to do the following:
>>> serial_date_to_string(15951) # arg is number of days since 1970
"2013-09-02"
This is different from Python: Converting Epoch time into the datetime because I am starting with days since 1970. I not sure if you can just multiply by 86,400 due to leap seconds, etc.
datetime.datetime(1970, 1, 1, 0, 0) + datetime.timedelta(15951)
– Embryologydatetime.datetime(1970,1,1) + datetime.timedelta(15951 - 1)
– Coamingepoch = datetime.datetime.utcfromtimestamp(0)
to get the epoch datetime, instead of hardcoding. then follow @SSNR – Mycah