Advertisement
Spocoman

13. Holidays Between Two Dates

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