I need to determine the time until midnight.
These calculations are correct:
From 11:00 am to 12:00 pm = 01:00
From 00:00 am to 11:00 pm = 11:00
From 11:00 am to 01:00 pm = 02:00
But when the next time is calculated the result is not correct:
From 11:00 PM Until 00:00 AM = -23: 00
From 11:00 PM Until 12:00 AM = -23: 00
Here I would expect it to be = 01:00
That's what really needs to be determined, the time until midnight.
I'm doing it this way:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>00:00:00 AM</asp:ListItem>
<asp:ListItem>11:00:00 AM</asp:ListItem>
<asp:ListItem>12:00:00 PM</asp:ListItem>
<asp:ListItem>10:00:00 PM</asp:ListItem>
<asp:ListItem>11:00:00 PM</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>00:00:00 AM</asp:ListItem>
<asp:ListItem>11:00:00 AM</asp:ListItem>
<asp:ListItem>12:00:00 PM</asp:ListItem>
<asp:ListItem>01:00:00 PM</asp:ListItem>
<asp:ListItem>12:00:00 AM</asp:ListItem>
<asp:ListItem>11:00:00 PM</asp:ListItem>
</asp:DropDownList>
And the calculation is done as follows:
Dim horaInicio As DateTime = DropDownList1.SelectedItem.Text
Dim horaFin As DateTime = DropDownList2.SelectedItem.Text
Dim diferencia As TimeSpan = horaFin.Subtract(horaInicio)
TextBox1.Text = diferencia.ToString()