Odoo Help

0

0
3 Answers
0
Avatar

Ibrahim

--Ibrahim--
2807
| 6 3 7
Casablanca, Morocco
--Ibrahim--


Ibrahim
2018/11/19 3:57

Hi, 
try : 

num_days = abs(fields.Datetime.from_string(t1) - fields.Datetime.from_string(t2)).days
num_seconds = abs(fields.Datetime.from_string(t1) - fields.Datetime.from_string(t2)).seconds
num_hours = parking_end_days * 24 + parking_end_seconds // 3600
num_minutes = parking_end_days * 24 + parking_end_seconds // 60

Thanks
0
Avatar

Hilar AK

--Hilar AK--
9121
| 6 6 11
Switzerland
--Hilar AK--
  Blog:-
        https://hilarlive.wordpress.com/
  StackOverflow:
        http://stackoverflow.com/users/7561347/burmese-pythis

Quora:
    

            https://www.quora.com/profile/Hilar-Ak-1

Experienced Odoo developer, Functional Consultant.



Hilar AK
2018/11/16 9:19

While interpreting your lines I got the correct result.

import datetime as datetime
t1 = datetime.datetime.strptime('11/16/2019 08:00:00', '%m/%d/%Y %H:%M:%S')
t2 = datetime.datetime.strptime('2019-11-16 09:00:00', '%Y-%m-%d %H:%M:%S')
t3 = t2-t1
x = float(t3.days) * 24 + (float(t3.seconds) / 3600)
print "t1:",t1, "t2:", t2, "t3:", t3, "result:", x
t1: 2019-11-16 08:00:00 t2: 2019-11-16 09:00:00 t3: 1:00:00 result: 1.0

Your problem arises when you find the difference from the small-time object with greater. so just add this condition.

if t2 > t1:
t3 = t2-t1
else:
t3 = t1 - t2



1 Comment
Dishon Kadoh
2018/11/17 5:46

I added the condition but it didn't work it was now giving me a difference of positive 3 however i got a solution by adding 3 hours to t2 using

t2 = t2 + timedelta(hours=3)

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now