jukes1
asked on
Compare times stored in dropdownlists?
I am collecting information from my affiliated stores about their store hours. I have dropdownlists populated with the hours in the day, incremented by half hours. This dropdownlist is actually a subclass of the DropDownList WebControl that automatically loads the times.
I am trying to use a validator to ensure that the closing time is greater than the open time. Unfortunatley, I can't seem to get the validator class to agree that the times can be compared as dates... can anyone help?
As an example,
ddlOpen.SelectedItem.Value = "12:00 AM"
ddlClose.SelectedItem.Valu e = "1:00 PM"
and
ddlOpen.SelectedItem.Value = "1:00 PM"
ddlClose.SelectedItem.Valu e = "12:00 AM"
Both validate as false.
Also, if I try to validate the dropdownlist as a "Date" data type, it also fails. This behavior happens regardless of how I store the Value string (ie, long date/time, or short date).
I am trying to use a validator to ensure that the closing time is greater than the open time. Unfortunatley, I can't seem to get the validator class to agree that the times can be compared as dates... can anyone help?
As an example,
ddlOpen.SelectedItem.Value
ddlClose.SelectedItem.Valu
and
ddlOpen.SelectedItem.Value
ddlClose.SelectedItem.Valu
Both validate as false.
Also, if I try to validate the dropdownlist as a "Date" data type, it also fails. This behavior happens regardless of how I store the Value string (ie, long date/time, or short date).
How about setting the value column as military time.
.Text = "6:00 AM"
.Value = "600"
.Text = "1:00 PM"
.Value = "1300"
etc.
Then just compare the values as Numbers.
.Text = "6:00 AM"
.Value = "600"
.Text = "1:00 PM"
.Value = "1300"
etc.
Then just compare the values as Numbers.
ASKER
TheLearnedOne,
I'm not sure what you mean by "what does the validation expression look like?"
The validator is added visually in visual studio, its controls and comprison operator are assigned, and its type is set to Date.
mdamico,
Do you know how to convert a date into a military time string, and then how to generate a datetime from a military time value? If you do, I could probably do it.
I'm not sure what you mean by "what does the validation expression look like?"
The validator is added visually in visual studio, its controls and comprison operator are assigned, and its type is set to Date.
mdamico,
Do you know how to convert a date into a military time string, and then how to generate a datetime from a military time value? If you do, I could probably do it.
thedate.ToString("HHmm")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bob