anizko

13. Holidays Between Two Dates

May 18th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Globalization;
  7.  
  8. namespace _13.Debug_the_Code_Holidays_Between_Two_Dates
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             {
  15.                 var startDate = DateTime.ParseExact(Console.ReadLine(),
  16.                     "d.M.yyyy", CultureInfo.InvariantCulture);
  17.  
  18.                 var endDate = DateTime.ParseExact(Console.ReadLine(),
  19.                     "d.M.yyyy", CultureInfo.InvariantCulture);
  20.  
  21.                 var holidaysCount = 0;
  22.  
  23.                 for (var date = startDate; date <= endDate; date=date.AddDays(1))
  24.                 {
  25.  
  26.                     if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
  27.                     {
  28.                         holidaysCount++;
  29.                     }
  30.                 }
  31.  
  32.                 Console.WriteLine(holidaysCount);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment