To allocate enough space for an array element for each day of the week, I am trying to determine the maximum number of rows I need. This led me to the question of how I would work.
Could you calculate the number of days in a year for the next n years and go with this? Or is there (as I suspect) a more elegant solution that includes numbers 365, 366, 2, and 7?
Which libraries will help?
The maximum number of days in a year is 366, which gives us 52 full weeks. In those 52 weeks there are at least 52 * 5 = 260 business days.
2 (52 * 7 = 364), , 2 .
, 262.
, , , 14 : ( , ).
, , , 364 , 7 (, , 5 x 52 = 260 364 ).
, 1-2 .
, - 262.
, , , . , , .
cletus GvS , , . , , 53 5 , ergo 265 . 52 , , .
, - , . .
And you save at least 10 minutes by working out the exact solution (well, that I would probably need at least ;-), which you can spend on coding.
According to this site
http://kalender-365.de/weekdays.php
In the period from February 1, 2012 to February 1, 2013, 263 business days exceed the maximum of 262 stated above.
Here's how you could calculate the exact number of week days in a particular year using C # (.NET Framework):
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { // in which year which should count week days var year = DateTime.Now.Year; // first day of this year var date = new DateTime(year, 1, 1); var count = 0; // if date is still within our year, proceed while (date.Year < year + 1) { if (date.DayOfWeek == DayOfWeek.Monday || date.DayOfWeek == DayOfWeek.Tuesday || date.DayOfWeek == DayOfWeek.Wednesday || date.DayOfWeek == DayOfWeek.Thursday || date.DayOfWeek == DayOfWeek.Friday) { count++; } date.AddDays(1); } Console.Write(count); } } }