Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace DateThing
- {
- class Dates
- {
- static void Main()
- {
- var holidays = new List<DateTime>()
- {
- new DateTime(2014,01,01),
- new DateTime(2014,03,03),
- new DateTime(2014,04,18),
- new DateTime(2014,04,19),
- new DateTime(2014,04,20),
- new DateTime(2014,05,01),
- new DateTime(2014,05,06),
- new DateTime(2014,05,02),
- new DateTime(2014,05,05),
- new DateTime(2014,05,24),
- new DateTime(2014,09,06),
- new DateTime(2014,09,22),
- new DateTime(2014,11,01),
- new DateTime(2014,12,24),
- new DateTime(2014,12,25),
- new DateTime(2014,12,26),
- new DateTime(2014,12,31),
- };
- var workingSaturdays = new List<DateTime>()
- {
- new DateTime(2014, 05, 10),
- new DateTime(2014, 05, 31),
- new DateTime(2014, 12, 13),
- };
- Console.Write("From: ");
- string firstDate = Console.ReadLine();
- DateTime start = Convert.ToDateTime(firstDate);
- Console.Write("To: ");
- string finalDate = Console.ReadLine();
- DateTime toDate = Convert.ToDateTime(finalDate);
- int workingdayscount = 0;
- int nonworkingdayscount = 0;
- List<DateTime> nonworkingdayslist = new List<DateTime>();
- for (DateTime i = start; i <= toDate ; i=i.AddDays(1) )
- {
- if (i.DayOfWeek == DayOfWeek.Saturday && workingSaturdays.Contains(i))
- {
- workingdayscount++;
- }
- else if (i.DayOfWeek != DayOfWeek.Sunday && i.DayOfWeek != DayOfWeek.Saturday &&
- holidays.Contains(i))
- {
- nonworkingdayscount++;
- nonworkingdayslist.Add(i);
- }
- else if (i.DayOfWeek == DayOfWeek.Sunday || i.DayOfWeek == DayOfWeek.Saturday)
- {
- nonworkingdayscount++;
- nonworkingdayslist.Add(i);
- }
- else
- {
- workingdayscount++;
- }
- }
- Console.WriteLine("From {0} to {1}:",start.ToString("d"),toDate.ToString("d"));
- Console.WriteLine("Working days = {0}",workingdayscount);
- Console.WriteLine("Non-working days = {0}",nonworkingdayscount);
- Console.WriteLine("\nHolidays:");
- foreach (var holiday in nonworkingdayslist)
- {
- Console.WriteLine(holiday.ToString("d"));
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment