Advertisement
martyz

Count Working Days

Oct 20th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace CountWorkingDays
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.            
  15.             DateTime startDate = Convert.ToDateTime(Console.ReadLine());
  16.             DateTime endDate = Convert.ToDateTime(Console.ReadLine());
  17.             //DateTime startDate = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);
  18.             //DateTime endDate = DateTime.ParseExact(Console.ReadLine(), "dd-MM-yyyy", CultureInfo.InvariantCulture);
  19.             int count = 0;
  20.  
  21.  
  22.             List<DateTime> dt = "01-01 03-03 01-05 06-05 24-05 06-09 22-09 01-11 24-12 25-12 26-12"
  23.                 .Split(' ').
  24.                 Select(x => Convert.ToDateTime(x))
  25.                 .ToList();
  26.  
  27.  
  28.             for (var day = startDate.Date; day <= endDate.Date; day = day.AddDays(1))
  29.             {
  30.  
  31.                
  32.                 if (day.DayOfWeek == DayOfWeek.Saturday || day.DayOfWeek ==  DayOfWeek.Sunday)
  33.                 {
  34.                     //count++;
  35.                 } else if (dt.Any(x => x.Day == day.Day && x.Month == day.Month ))
  36.                 {
  37.                     //count++;
  38.                 }
  39.                 else
  40.                 {
  41.                     count++;
  42.                 }
  43.  
  44.             }
  45.             Console.WriteLine(count);
  46.  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement