Advertisement
fbinnzhivko

Untitled

Jun 13th, 2016
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. class CountWorkingDays
  5. {
  6.     static void Main()
  7.     {
  8.         string startDateText = Console.ReadLine();
  9.         string endDateText = Console.ReadLine();
  10.  
  11.         DateTime startDate = DateTime.ParseExact(startDateText, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  12.         DateTime endDate = DateTime.ParseExact(endDateText, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  13.  
  14.         DateTime[] holidays = new DateTime[12];
  15.  
  16.         holidays[0] = new DateTime(4, 01, 01);
  17.         holidays[1] = new DateTime(4, 03, 03);
  18.         holidays[2] = new DateTime(4, 05, 01);
  19.         holidays[3] = new DateTime(4, 05, 06);
  20.         holidays[4] = new DateTime(4, 05, 24);
  21.         holidays[5] = new DateTime(4, 09, 06);
  22.         holidays[6] = new DateTime(4, 09, 22);
  23.         holidays[7] = new DateTime(4, 11, 01);
  24.         holidays[9] = new DateTime(4, 12, 24);
  25.         holidays[10] = new DateTime(4, 12, 25);
  26.         holidays[11] = new DateTime(4, 12, 26);
  27.  
  28.         int workingDayCounter = 0;
  29.  
  30.         for (DateTime i = startDate; i <= endDate; i = i.AddDays(1))
  31.         {
  32.             DayOfWeek day = i.DayOfWeek;
  33.  
  34.             DateTime temp = new DateTime(4, i.Month, i.Day);
  35.  
  36.             if (!holidays.Contains(temp) && (!day.Equals(DayOfWeek.Saturday) && !day.Equals(DayOfWeek.Sunday)))
  37.             {
  38.                 workingDayCounter++;
  39.             }
  40.         }
  41.         Console.WriteLine(workingDayCounter);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement