Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5582 Vizualizări

In the "Leave request" it calculates duration between From and To, But it will calculate the sunday and saturday i don't want to calculate these two dates.

I hope U can understand my problem

Thanks in advance

Sorryyyyyyyy for my bad english

Imagine profil
Abandonează
Cel mai bun răspuns

Hi Madhubabu,

Following code may help you to count number of days between two dates except weekends.

>>> from datetime import date,timedelta
>>> fromdate = date(2014, 4, 1)
>>> todate = date(2014, 4, 30)
>>> daygenerator = [fromdate + timedelta(x + 1) for x in xrange((todate - fromdate).days)]
>>> daygenerator += [fromdate + timedelta(0)]
>>> sum(1 for day in daygenerator if day.weekday() < 5)
22

Hope this may help you.

Imagine profil
Abandonează
Autor

Thanks a lot Sudhir Arya. It's working fine.