0
I made a little program in python that he takes the current time, the time, convert in seconds and subtract from each other to know the difference between him. My doubt is, how do I convert these seconds to hours and days?
Code that converts the date to seconds:
from datetime import date, datetime
import time
date_now = time.mktime(datetime.now().timetuple())
date_created = time.mktime(get_demand_if_exist[0].date_created.timetuple())
diff_time = abs(date_now - date_created)
Exactly what I needed, because I just needed to calculate the days/hours with the seconds I could. Thank you!
– Ikaro Pinheiro
It is better to use a subtraction of two objects
datetime
, that in Python creates an objtotimedelta
- see the other answer. (The packagearrow
is unnecessary, in fact). This answer is good if you already have the diffraction of fear between seconds - but if you have dates, Python datetime will already count months and years with variable duration, etc...– jsbueno
@jsbueno, I explained the use of Arrow in the comets of my answer, my example would be given without Arrow, but datetime required that the first date of the example would have to be "complete" (including seconds), as I don’t know where the date he was getting would come from (database?) I thought Arrow would make it easier. Arrow is a 10. :-)
– Sidon