Question : calculate timespan after midnight

Lets say I have two date time picker controls, 1 and 2
a textbox and a button.

The datetimepickers are in a custom format-hh:mm tt- to display time only.

The below code can get the timespan between a start time and and end time.

My problem is where the start time is say 11.00PM and the stop time is 01.15AM.
I realise that this is the next day whilst the date time picker date hasn't changed at all.

How do i solve the problem?
The other problem is that the datetimepickers cannot display midnight valuess ie 00.15 for example.
How can i show midnight times in a date time picker?
1:
2:
3:
4:
5:
6:
7:
8:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim starttime As DateTime = DateTimePicker1.Value
        Dim endtime As DateTime = DateTimePicker2.Value

        Dim results As TimeSpan = starttime - endtime
        TextBox1.Text = results.Duration.ToString

    End Sub

Answer : calculate timespan after midnight

To solve your first problem, if it's always the next day, try this:


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim starttime As DateTime = DateTimePicker1.Value
        Dim endtime As DateTime = DateTimePicker2.Value
        If endtime < starttime then
            endtime=endtime.AddDays(1)
        End If
        Dim results As TimeSpan = starttime - endtime
        TextBox1.Text = results.Duration.ToString

    End Sub
Random Solutions  
 
programming4us programming4us