Radost09

Holidays Between Two Dates

Jan 28th, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using System.Globalization;
  2.  
  3. namespace P13_Holidays_Between_Two_Dates
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var startDate = DateTime.ParseExact(Console.ReadLine(),
  10.             "dd.m.yyyy", CultureInfo.InvariantCulture);
  11.             var endDate = DateTime.ParseExact(Console.ReadLine(),
  12.             "dd.m.yyyy", CultureInfo.InvariantCulture);
  13.             var holidaysCount = 0;
  14.             for (var date = startDate; date <= endDate; date.AddDays(1))
  15.                 if (date.DayOfWeek == DayOfWeek.Saturday &&
  16.                     date.DayOfWeek == DayOfWeek.Sunday)
  17.                     holidaysCount++;
  18.             Console.WriteLine(holidaysCount);
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment