hello
HOW I CAN CALCULATE DIFFERENCE BETWEEN TWO DATE
for record in self:
record['x_studio_total_jours'] = record['x_studio_date_departe'] - record['x_studio_date_arrive']
the code is correct ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
hello
HOW I CAN CALCULATE DIFFERENCE BETWEEN TWO DATE
for record in self:
record['x_studio_total_jours'] = record['x_studio_date_departe'] - record['x_studio_date_arrive']
the code is correct ?
Hi
Try this code
for record in self:
record['x_studio_total_days'] = 0
if record['x_studio_date_arrive'] and record['x_studio_date_departure']:
record['x_studio_total_days'] = (record['x_studio_date_departure'] - record['x_studio_date_arrive']).days

Hi,
Refer to the code
from datetime import datetime
for record in self:
if record['x_studio_date_departe'] and record['x_studio_date_arrive']:
depart_date = fields.Datetime.from_string(record['x_studio_date_departe'])
arrive_date = fields.Datetime.from_string(record['x_studio_date_arrive'])
difference = (arrive_date - depart_date).days
record['x_studio_total_jours'] = difference
else:
record['x_studio_total_jours'] = 0 # Handle the case where one or both dates are not set
In this code:
Make sure you have the fields module imported in your file for this code to work properly.
Hope it helps
| 관련 게시물 | 답글 | 화면 | 활동 | |
|---|---|---|---|---|
|
2
4월 21
|
4059 | |||
|
3
10월 25
|
3956 | |||
|
1
2월 24
|
6000 | |||
|
0
4월 21
|
4917 | |||
|
2
7월 25
|
1492 |
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.
Hi Please refer,
https://www.odoo.com/forum/help-1/how-to-calculate-date-difference-using-datetime-103054
Hope it helps