Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two time period suppose 1 is 11:55:40 and 13:30:20. i want to check 12:00:00 time is between in those two times plz help me?
Posted
Updated 3-Apr-14 23:18pm
v4

Might be time span will help you. Give it a try.

http://www.dotnetperls.com/timespan[^]
 
Share this answer
 
To work with time values only (independant of date) try:
C#
TimeSpan tsStart = new TimeSpan(11, 55, 40);
TimeSpan tsEnd = new TimeSpan(13, 30, 20);
TimeSpan tsCheck = new TimeSpan(12, 0, 0);
if (tsStart <= tsCheck && tsCheck <= tsEnd)
    {
    Console.WriteLine("In period");
    }
But normally, you would work with DateTime objects:
C#
DateTime dtStart = DateTime.Parse("11:55:40");
DateTime dtEnd = DateTime.Parse("13:30:20");
DateTime dtCheck = DateTime.Now;
if (dtStart <= dtCheck && dtCheck <= dtEnd)
    {
    Console.WriteLine("In period");
    }
 
Share this answer
 
Please try with below code.

protected void Page_Load(object sender, EventArgs e)
{
string a = "11:55:40";
string b = "13:30:20";
string c = "12:00:00";
DateTime dta = Convert.ToDateTime(a);
DateTime dtb = Convert.ToDateTime(b);
DateTime dtc = Convert.ToDateTime(c);
if (dta < dtc && dtc < dtb)
{
Response.Write("Cond success");
}

}
 
Share this answer
 
if(1stTime<12.00 && 2ndTime>12.00)
{
  //Yes
}
else
{
   //No
}
 
Share this answer
 
Check this article, it'll save lot of time for other questions related to time.
Time Period Library for .NET[^]
 
Share this answer
 

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