Skip to Content
Menu
This question has been flagged
1 Reply
875 Views

Can I calculate the different in two giving date fields in different field using Compute in Odoo 

Avatar
Discard
Best Answer

Hi,

See the sample:


from datetime import datetime

def days_between(d1, d2):
d1 = datetime.strptime(d1, "%Y-%m-%d")
d2 = datetime.strptime(d2, "%Y-%m-%d")
return abs((d2 - d1).days)

Thanks

Avatar
Discard
Author

Niyas

Thanks for replying to me

But I want to use computed field to get automated calculation. And I need to define date start field and date end field - so how can I do that

You just have to create your functional field and use the above code to get the difference between the 2 dates.