-7

I want my program to check the present system time and use it to display whether the time at that moment is off peak or peak. please help. thanks

2 Answers2

3

try this:

        if (
                DateTime.Now.DayOfWeek != DayOfWeek.Saturday &&  // it's not saturday
                DateTime.Now.DayOfWeek != DayOfWeek.Sunday &&    // it's not sunday
                DateTime.Now.Hour>=8 && DateTime.Now.Hour < 17)   // it is 08:00 to 16:59
            {
                // work time
            }
bytecode77
  • 14,163
  • 30
  • 110
  • 141
-1
DateTime start = new DateTime(2009, 12, 9, 10, 0, 0)); //10 o'clock
DateTime end = new DateTime(2009, 12, 10, 12, 0, 0)); //12 o'clock
DateTime now = DateTime.Now;

if ((now > start) && (now < end))
{
   //match found
}
Kishore Kumar
  • 12,675
  • 27
  • 97
  • 154