Function to calculate number of days between FROM and TO but it won't calculate weekends(sat and sun) ?
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
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.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 4/29/14, 2:10 PM|
|Seen: 1118 times|
|Last updated: 3/16/15, 8:10 AM|