I have two times like t1= "2018-04-28 10:32:32+00:00"
and t2= "2018-04-29 20:32:32+00:00"
Need to find the number of days between these two days. Actually in the above two days there is 36(means 1 and half day) hours difference is there so I need output as 1.5(which mean 1day and half day). How this is possible with python
Asked
Active
Viewed 120 times
-2

U13-Forward
- 69,221
- 14
- 89
- 114

user3202086
- 17
- 6
-
Please show us your attempt on the problem. – Fourier Jun 08 '18 at 12:49
-
refer this link https://stackoverflow.com/questions/1345827/how-do-i-find-the-time-difference-between-two-datetime-objects-in-python – Surya Tej Jun 08 '18 at 12:50
-
1This is two separate questions: [Converting a string time to a python datetime object](https://stackoverflow.com/questions/466345/converting-string-into-datetime) and [Finding the difference between two datetime objects](https://stackoverflow.com/questions/1345827/how-do-i-find-the-time-difference-between-two-datetime-objects-in-python). – glibdud Jun 08 '18 at 12:53
1 Answers
0
You can use the timedelta
in datetime
module. I used parse
for more date parsing.
In [2]: from dateutil.parser import parse
In [3]: d1 = parse("2018-04-28 10:32:32+00:00")
In [4]: d2 = parse("2018-04-29 20:32:32+00:00")
In [5]: de = d2 - d1
In [6]: de.total_seconds()/ (60 * 60 * 24)
Out[6]: 1.4166666666666667

iDrwish
- 3,085
- 1
- 15
- 24