PDA

Click to See Complete Forum and Search --> : Get number of weekdays between two dates.


Arc
May 8th, 2008, 10:52 PM
Hey guys, I was wondering if anyone had written a function that will return the number of work days between two dates. I figured this has been done many times, but I can't figure out how to go about it.

For instance if I put in the dates 2008-04-19 and 2008-05-02 it would return the number of days between those two dates minus weekends. Well not just between, it would also include those two days.

I was thinking of looping thru the dates somehow and using the date function to check if that date is a Sat or Sun using the Date("l") function, but I am not sure how to loop thru dates because you also have to know how many days are in the month and then start in the new month if the dates cross between two months...etc.

Anyone have any input? Thanks.

penagate
May 9th, 2008, 12:25 AM
There's no need to loop through the lot: just find first Monday and last Friday in the range and multiply the number of days by 5/7ths, then add the head and tail days.


But what about public holidays?

Arc
May 9th, 2008, 02:13 PM
I am not sure what you mean, that doesn't seem like it would be accurate. Also I am not even sure how to find the first monday and last friday and what about the days before the first monday and after the last friday? For instance, what if the first monday is 6 days after the first date, like if the first date was a tuesday? And what if the last friday was 6 days before the last date which was a thursday?

I am not worried about holidays, because I have no way of knowing exactly which holidays these business will be taking off. Some businesses close on every holiday, some are open even on Christmas.

Thanks for the help, I am just not clear on it.