View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default datetimepicker finding the hours between two dates

Check out help on DATEDIFF() function

http://msdn.microsoft.com/en-us/libr...6f(VS.80).aspx

--
Jacob


"SteveZmyname" wrote:

Hello
Just like the subject says I am using two datetimepickers a start and end
and would like to know the hours between the two (or days). So far I have

Private Sub calcHours()
Dim totalHours As Integer
'totalHours = DateInitiatedDateTimePicker.Value.Day -
DateFinishedDateTimePicker.Value.Day
Dim startDate As DateTime = DateInitiatedDateTimePicker.Value
Dim finishDate As DateTime = DateFinishedDateTimePicker.Value
totalHours = startDate.Day + finishDate.Day
'totalHours = DateFinishedDateTimePicker.Value.Day -
DateInitiatedDateTimePicker.Value.Day
HoursTextBox.Text = totalHours
MessageBox.Show(totalHours)
End Sub

Not sure whether to add or subtract the dates. If I subtract then I always
get a 0.
If I add using the dates 1/15/2010 for start and 2/2/2010 for end I get a
value of 10.
This doesn't make sense to me for either hours or days.