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
Asked
Active
Viewed 1,976 times
-7
-
how do you define "peak" and "off peak"? – scibuff Mar 22 '12 at 10:25
-
so what is your question and what did you try so far? – QQping Mar 22 '12 at 10:26
-
1if(IsPeak(DateTime.Now)){ // etc. } LOL – JP Hellemons Mar 22 '12 at 10:26
-
http://stackoverflow.com/questions/1504494/c-sharp-find-if-current-time-falls-in-a-time-range – Scroog1 Mar 22 '12 at 10:27
-
Closers: If you don't get it go to next question. Ignorance is bliss. Question was clear. – Nime Cloud Jul 03 '13 at 11:10
2 Answers
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
-
Well you have peak time span there but why not saturday and sundays ? – V4Vendetta Mar 22 '12 at 10:30
-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
-
-
I think the OP wants to check on a certain time on every day. Take a look at my answer. – bytecode77 Mar 23 '12 at 16:05