Hi all, I want to compare current time with between 7 to 8am & 8am to 8pm. Kindly suggest me how to make it happen

Hi all,

I want to compare current time with between 7 to 8am & 8am to 8pm.

First Condition : Current time is between 7 am to 8 am

Second Condition : Current time is between 8 am to 8 pm

Kindly suggest me how to make it happen.

    TimeSpan time7AM = new TimeSpan(7, 0, 0) //7AM
    TimeSpan time8AM = new TimeSpan(8, 0, 0) //8AM
    TimeSpan time8PM = new TimeSpan(20, 0, 0) //8PM
    TimeSpan now = DateTime.Now.TimeOfDay

    if ((now > time7AM) AND (now < time8AM))
    {
       //match found for first condition
    }
    else
    if ((now > time8AM) AND (now < time8PM))
    {
       //match found for second condition
    }

Regards,
Karthik Byggari

1 Like

Thanks Bro

1 Like

Can you mark my previous post as solution if that worked for you. Thanks :slight_smile: