Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two dropdownlist ddlStartTime and ddlEndTime. In both dropdownlists time is filled with 5 minute intervals e.g. 12:00 AM, 12:05 AM, 12:10 AM upto 11.55 PM.
I want to implement server side validation so that endtime can't be less than starttime. How to do this?
Posted
Updated 22-Jul-15 1:01am
v2

1 solution

Use DateTime.ParseExact:
C#
DateTime dtStart = DateTime.ParseExact("12:00 AM", "hh:mm tt", CultureInfo.InvariantCulture);
DateTime dtEnd = DateTime.ParseExact("10:00 PM", "hh:mm tt", CultureInfo.InvariantCulture);
Replace the constant times with your drop down values, and you can compare the two DateTime values directly.
 
Share this answer
 
Comments
Thanks7872 22-Jul-15 7:50am    
..using this may be : https://msdn.microsoft.com/en-us/library/system.datetime.compare(v=vs.110).aspx
xpertzgurtej 22-Jul-15 7:50am    
Thanks OriginalGriff for your help..it solved my problem.
OriginalGriff 22-Jul-15 7:58am    
You're welcome!

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