0

I have in Python 3.7 a date in form of an integer that represents the number of hours from 1/1/1900 00 Hours. Can I transform it into string of format dd/mm/yyyy?

for example:

timenumber = 1043148
timestring = magictrickfunctions(timenumber)
print(timestring)

should give "01/01/2017"

AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
Štěpán Šubík
  • 109
  • 2
  • 3
  • 10
  • Multiply it by `60 * 60`, then it’s a regular UNIX time stamp…!? – deceze Apr 09 '20 at 20:29
  • Each of the steps for this is covered well elsewhere on this site and on line. I've covered this with the critical conversion link; the rest is simple arithmetic. – Prune Apr 09 '20 at 21:06
  • No, Prune. The solution you have suggested was not functioning. The answer by AzyCrw4282 was nowhere to be found. – Štěpán Šubík Apr 12 '20 at 08:15

1 Answers1

1

Are you sure it gives you 01/01/2017 instead of 01/01/2019?

To obtain the number of days divide your total hours by /24 this will give you the number of days. You can then specify that as shown below. I am using pandas library here.

import pandas as pd
start_date  = "01/01/1900"
date_1 = pd.to_datetime(start_date)
end_date = date_1 + pd.DateOffset(days=43464) #specify the number of days and add it to your start_date
print(end_date)

Outtput

2019-01-01 00:00:00
AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35