How many weekdays between two dates

Hello, I'm starting to learn Objective-C and I'm doing the first experiments. In particular,I'm starting to build applications that work with dates. Thanks to Apple's guides areable to understand how to calculate the days between two dates, but now I want to extend the capabilities of the application. In particular I would like that given time interval, and the number of days you could know how many Mondays, Tuesdays, and so we are. I searched far and wide but I can not find anything about it. At most I could get the number of days of the week for a specified day. Can anyone help me? Thank you.

Posted on Apr 15, 2012 6:37 AM

Reply
1 reply

Apr 15, 2012 8:08 AM in response to ABRSM

You'll need to calculate the day of the week the first date of you sequence is on. Once you have that it's just a matter of seeing how long your interval is seeing hom many times 7 (the number of days in a week) goes into it evenly. That will give you the number of each day in the sequence.


So for example if the sequence starts on Sunday and the length is 7 you have one of each day ( 7/7 = 1) If the sequence was 14 day long you' have 2 of each day (14/7 = 2).


If the length of the sequence divided by 7 leaves a remainder then the remainder is the number of extra days starting from the first day. So for example if the length of the sequence is 9 you have 9/7 = 1 with a remainder of 3 so you have 1 of each day plus 1 more Sunday, Monday and Tuesday.


The big thing is calculating the day of the week the first date in your sequence falls on. Once you have that the rest is just basic calculation.


Start here Determination of the day of the week. It is also possible that there is a class in the libraries to o this for you.


good luck

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How many weekdays between two dates

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.