Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 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 _01.CountWorkingDays
  9. {
  10. class CountWorkingDays
  11. {
  12. static void Main()
  13. {
  14. //Console.Write("Write first date in format dd-MM-yyyy: ");
  15. string input = Console.ReadLine();
  16. DateTime firstDate = DateTime.ParseExact(input, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  17.  
  18. //Console.Write("Write second date in format dd-MM-yyyy: ");
  19. input = Console.ReadLine();
  20. DateTime secondDate = DateTime.ParseExact(input, "dd-MM-yyyy", CultureInfo.InvariantCulture);
  21.  
  22. DateTime[] nonWorkingDays = new DateTime[]
  23. {
  24. new DateTime(firstDate.Year, 01, 01),
  25. new DateTime(firstDate.Year, 03, 03),
  26. new DateTime(firstDate.Year, 05, 01),
  27. new DateTime(firstDate.Year, 05, 06),
  28. new DateTime(firstDate.Year, 05, 24),
  29. new DateTime(firstDate.Year, 09, 06),
  30. new DateTime(firstDate.Year, 09, 22),
  31. new DateTime(firstDate.Year, 11, 01),
  32. new DateTime(firstDate.Year, 12, 24),
  33. new DateTime(firstDate.Year, 12, 25),
  34. new DateTime(firstDate.Year, 12, 26)
  35. };
  36.  
  37. int totalDays = (secondDate - firstDate).Days;
  38. int countWorkingDays = 0;
  39. DateTime currentDay = new DateTime();
  40.  
  41. for (double i = 0; i <= totalDays; i++)
  42. {
  43. currentDay = firstDate.AddDays(i);
  44. if (!(currentDay.DayOfWeek.ToString() == "Saturday" || currentDay.DayOfWeek.ToString() == "Sunday"))
  45. {
  46. if (!nonWorkingDays.Contains(currentDay))
  47. {
  48. countWorkingDays++;
  49. }
  50. }
  51. }
  52.  
  53. Console.WriteLine(countWorkingDays);
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement