Display different message based on if condition using C# in ASP.Net

Last Reply on Oct 25, 2017 04:42 AM By kalpesh

Posted on Oct 25, 2017 04:13 AM

Dear All,

I'm little bit confused about my code i.e. I want to display the message if the time is less than 8:00 AM in the morning and if the time is greater than 17:00 (PM) it should display message no meeting to display else the time is between 8:00-17:00 different message.

 TimeSpan start = TimeSpan.Parse("08:00"); // 10 PM
            TimeSpan end = TimeSpan.Parse("16:30");   // 2 AM
            TimeSpan now = DateTime.Now.TimeOfDay;
           string timespan= now.ToString(@"hh\:mm");

            if (now <= start && now >= end)
            {
                lbl_availabletime.Text = "No more upcoming appointemtns for the day";
            }
            else
            {
                lbl_availabletime.Text = "Available until " + currentdate1.ToString();
            }

Thanks

Posted on Oct 25, 2017 04:42 AM
irshad1231 says:
if (now <= start && now >= end)

If you just need to check current time not less than 8.00 AM and Not greater than 17:00 PM then replace with below line.

if (now.Hours < 8 || now.Hours >= 17)