Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts
I have timings like fromtime to Totime is Monday 10:30 AM to Wednesday 11:00 AM then how can i compare on Tuesday time with in the above timings.please help me


Thanks in Advance
Posted
Comments
Peter Leow 7-Feb-15 2:01am    
Not clear. Give some example.

1 solution

Not the most elegant way, but it is working:

C#
DateTime now = DateTime.Now;

if(
    (now.DayOfWeek == DayOfWeek.Monday && now.TimeOfDay >= TimeSpan.Parse("10:30"))
    || (now.DayOfWeek > DayOfWeek.Monday && now.DayOfWeek < DayOfWeek.Wednesday)
    || (now.DayOfWeek == DayOfWeek.Wednesday && now.TimeOfDay <= TimeSpan.Parse("11:00"))
  )
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}
 
Share this answer
 
Comments
NaniCh 11-Feb-15 1:29am    
Thanks for your help Zoltán Zörgő..
from the above scenario i have a doubt
how to calculate Monday 11:00 AM to Tuesday 04:00 AM when user at Tuesday 01:00 AM..
please help me
Zoltán Zörgő 11-Feb-15 7:50am    
Don't have doubts. Try it. For that you can use LinqPad.

DateTime now = DateTime.Parse("2015.02.10 01:00");

if(
(now.DayOfWeek == DayOfWeek.Monday && now.TimeOfDay >= TimeSpan.Parse("11:00"))
|| (now.DayOfWeek > DayOfWeek.Monday && now.DayOfWeek < DayOfWeek.Tuesday)
|| (now.DayOfWeek == DayOfWeek.Tuesday && now.TimeOfDay <= TimeSpan.Parse("04:00"))
)
{
Console.WriteLine("1");
}
else
{
Console.WriteLine("0");
}

Will yield 1 which is correct!
NaniCh 12-Feb-15 8:42am    
thanks for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900