Dianov

Basic Syntax, Conditional Statements and Loops - Lab (13. Holidays Between Two Dates)

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