hey guys, so i have been asked to create a booking program for a coach hire. i need help with quite a few things.

i have two DateTimePicker's. both are formated to time.
what i want to do is calculate the differnence between both times. so how can i take one DatetimePicker of another DatetimePicker. basically, the program asks the waiting time at the journey.

so if i take away the start and end time, and minus driving time. this will leave me with the waiting at journey time.

is there any ways to do this?

p.s. I have visual Basic 2005

You may be looking for the TimeSpan class. DateTime.Subtract(another Date) will return a TimeSpan, and from that you can obtain the difference in hours, minutes, seconds, etc. Example:

Dim startTime As DateTime = New DateTime(2010, 2, 5, 18, 0, 0)
        Dim endTime As DateTime = New DateTime(2010, 2, 5, 19, 30, 0)

        Dim timeDifference As TimeSpan = endTime.Subtract(startTime)

        MessageBox.Show(timeDifference.TotalMinutes)

sorry i dont understand. i have called my start time 'cboStartTime' and my End time 'cboEndTime'

i dont get what (2010, 2, 5, 19, 30, 0) means
can you please write out what i must type in to my program. i have formatted the datetimepicker as time series. so i want to basically minus the start time off the end time.

i kind of get what you wrote but im unsure on how to declare my variables. i.e a text box would be for example TextBox = txtBox.text
what would i write for a datetimepicker..?

and also down get what you wrote in red

I was just declaring DateTime variables and giving them initial values as an example. (year, month, day, hour, minute, second)

To access the date of the picker, use DateTimePicker.Value. So you would write something like

Dim startTime as DateTime = cboStartTime.value

To store the start time in a variable. Do the same for the end time and then you can obtain the time difference as a TimeSpan.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.