How to calculate how many business days are between two dates?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-04-04T23:19:44Z Indexed on 2010/04/04 23:23 UTC
Read the original article Hit count: 220

Filed under:
|

A friend asked me yesterday if this was possible on the iPhone. I took a look at NSCalendar and all the related Classes but couldn't find a solution to this.

So I thought about this approach: If I had two dates dateA and dateB, I would have to make a for-loop and iterate over every single day in this interval. Then I would count the business days monday until friday, and return the result.

Then I went to bed, and I woke up with this probably much better idea: I need to know what day is it when I start. Lets say it's thursday. And then I must know how many days are in that interval. The last part is not hard to figure out. For the first part, I have no clue yet, but I believe there's an day of week value in NSCalendar. With that, I could do some simple math to calculate the amount of business days.

Did anyone do that already on the iPhone?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about datetime