Click here to Skip to main content
15,513,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two comboboxes with times in intervals of 30mins. I need it so that when a confirm button is clicked it can validate that the time selected in first combobox is not after the time in the second combobox

What I have tried:

Not much T_T, need this for school programming project
Posted
Updated 30-Aug-22 19:32pm

OK, this is a simple compare, so what's the problem?

You're going to have to convert the strings from the combo's to actual time values, then it's a simple compare. You never said what the actual problem is so this about the best you're going to get until you do.
 
Share this answer
 
First, convert your time strings to DateTime values - see here: DateTime.ParseExact Method (System) | Microsoft Docs[^] and supply a format string which only contains Time elements, such as "HH:mm" for a 24 hour time, or "h:mm tt" for a 12 hour version - the case is important! (Formatting a DateTime for display - format string description[^] shows the format codes and what they mean). The exact format will depend on the values you put into your comboboxes.
That gives you two DateTime objects that you can do basic comparison with directly - DateTime.GreaterThan(DateTime, DateTime) Operator (System) | Microsoft Docs[^] for example.

Times can be confusing, since unless they contain a Date element, you have to assume that the day starts and ends at midnight: a shift that starts at 22:00 and ends at 06:00 can't be checked for "end greater than start" - for that, you need to include "2022-08-30 22:00" and "2022-08-31 06:00" which needs a more complicated control than a simple combobox!
 
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