Search This Blog

Thursday 15 December 2016

How to check time is between two times in c sharp?

TimeSpan startTime = new TimeSpan(9, 0, 0);
TimeSpan endTime = new TimeSpan(18, 0, 0);
TimeSpan now = DateTime.Now.TimeOfDay;
//TimeSpan now = new TimeSpan(0, 0, 0);

if (now >= startTime || end <= endTime)
{
            // Your code here..
}

Note:-

Time is calculate in 24-hour format

No comments:

Post a Comment