Here is my dataset.
emp_id|emp_name|work_start_date|work_end_date|days_worked_on|
------+--------+---------------+-------------+--------------+
1|A | 2023-03-01| 2023-03-03| 2|
2|B | 2023-03-04| 2023-03-04| 0|
Actually i want to calculate how many days the person worked on. so i calculated based on below query.
select
emp_id
,emp_name
,work_start_date
,work_end_date
,work_end_date - work_start_date as days_worked_on
from demo.stackquestions;
Ideally, the person-A worked on 03/01,03/02 and 03/03.Totally 3 days. But when calculate work_end_date - work_start_date , it is giving 2 days.(Technically Yes. But in reality the answer is wrong.) To calculate right days, do i need to add 1 (+1) at the end,
work_end_date - work_start_date +1 as days_worked_on
Is this right approach. Please share your thought on this.