I want to change time delta to integer value .
My code is as below.
import datetime
now = datetime.date.today()
print(now.toordinal()) # 736570
cali_date = datetime.data(2017, 6, 14)
print(cali_date.toordinal()) # 736494
date1 = now - cali_date
print(date1) # 76 days, 0:00:00
But, I want to get just 76
with integer.
How can I solve this problem?
Thank you.
There are two different ways of doing this conversion: the first one you divide the total_seconds() by the number of seconds in a minute, which is 60. the second approach, you divide the timedelta object by timedelta(minutes=1)
Just reference the days
attribute of the timedelta
object you have there:
print(date1.days)
There are also timedelta.seconds
and timedelta.microseconds
attributes, modeling the complete delta state.
date1
is a timedelta object - use date1.days
to get the number of days as an integer, or date1.total_seconds()
to see the number of seconds between the two datetime objects.
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