Advertisement
VelizarAvramov

10. Holidays Between Two Dates

Nov 17th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. namespace _10._Holidays_Between_Two_Dates
  5. {
  6.     class HollidayBetweenTwoDates
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var startDate = DateTime.ParseExact(Console.ReadLine(),
  11.             "d.M.yyyy", CultureInfo.InvariantCulture);
  12.  
  13.             var endDate = DateTime.ParseExact(Console.ReadLine(),
  14.                 "d.M.yyyy", CultureInfo.InvariantCulture);
  15.  
  16.             var holidaysCount = 0;
  17.  
  18.             for (var date = startDate; date <= endDate; date = date.AddDays(1))
  19.             {
  20.                 if (date.DayOfWeek == DayOfWeek.Saturday ||
  21.                     date.DayOfWeek == DayOfWeek.Sunday)
  22.                 {
  23.                     holidaysCount++;
  24.                 }
  25.             }
  26.             Console.WriteLine(holidaysCount);
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement