Hi,
I have two textboxes. One is the Start time and other is the end time. I need to check whether end time is greater than start time. I tried with Time Span but i need to check for Hours, Minutes, Second. If it returns with "(-)" then i need to validate. How to do that. Please find the following code.
.cs
====
DateTime dtStartTime = new DateTime();
DateTime dtEndTime = new DateTime();
TimeSpan dtDiff = new TimeSpan();
dtStartTime = Convert.ToDateTime(txtMonStarttime.Text.Trim());
dtEndTime = Convert.ToDateTime(txtMonEndtime.Text.Trim());
dtDiff = dtEndTime - dtStartTime;
Here if the dtDiff returns values with negative then i need to check and validate it. Please help.
Thanks,
Vijay
Loading
Pravin GhadgePosted Dec 23, 2011, 3:09 AM
u can also use:
DateTime dtStartTime = new DateTime();
DateTime dtEndTime = new DateTime();
TimeSpan dtDiff = new TimeSpan();
dtStartTime = Convert.ToDateTime(txtMonStarttime.Text.Trim());
dtEndTime = Convert.ToDateTime(txtMonEndtime.Text.Trim());
dtDiff = dtEndTime - dtStartTime;
if (dtDiff.Days < 0)
{
validatefunction()
}
vijay ragsPosted Dec 23, 2011, 2:43 AM
I tried with the following. As of now its working. But i dont know what was the exact impact in futher. I declared a string variable and check for "(-)" symbols using contains and validate it. Please let me know whether this approach is correct or not.
string timeSpan=string.Empty;
DateTime dtStartTime = new DateTime();
DateTime dtEndTime = new DateTime();
TimeSpan dtDiff = new TimeSpan();
dtStartTime = Convert.ToDateTime(txtMonStarttime.Text.Trim());
dtEndTime = Convert.ToDateTime(txtMonEndtime.Text.Trim());
dtDiff = dtEndTime - dtStartTime;
timeSpan=Convert.toString(dtDiff);
if(timeSpan.Contains('-'))
{
//Validate Function Call.
}