# how to calculate number of days worked by an employee between two dates?

By
SIEWE TIENTCHEU Marcelin
on 12/1/15, 3:43 AM 878 views

I created one salary rule for  seniority(antiquity: Number of days the employee has done in company)
i have the join date (from contract) and today of the employee..

what i want is how many days  between that two date.

ie: number of working days between two dates

#### Ankit H Gandhi(AHG)

--Ankit H Gandhi(AHG)--

1249
| 6 5 6
Baroda, India
--Ankit H Gandhi(AHG)--

Learning Python..

Ankit H Gandhi(AHG)
On 12/1/15, 6:27 AM

Dear Marcelin,

Using below code you will get number of days.

from datetime import datetime

format = '%Y-%m-%d'

start_date = '2015-12-01' -> Take your date field1

end_date = '2015-12-31' -> Take your date field2

start = datetime.strptime(start_date, format)

end = datetime.strptime(end_date, format)

daysDiff = str((end-start).days) -> will gives you 30 days

daysDiff = str((end-start).days + 1) -> will gives you 31 days

Hope this code help for you !!!

Thanks & Regards,

Ankit H Gandhi.

HappyOdoo
On 12/1/15, 4:48 AM

subtract two dates

if you are a developer then Use below query in your code :

select '2015-11-01'::date - '2015-11-30'::date-1;

This will give you:

30 days

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.

### Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

1 follower(s)

### Stats

 Asked: 12/1/15, 3:43 AM Seen: 878 times Last updated: 12/1/15, 6:30 AM