Search code examples
vb.netdatedatetimesumdatetimepicker

VB.NET Returning sum hours of datetimepicker


I have a SELECT that returns a column in datagridview called date and time of datetimepicker and also a column with the flag "input" or "output". I want to return a result with the sum of hours of datetimepicker with the flag "input" and another sum to the flag " ouput ". Could you help me guys?

Cheers....


Solution

  • But anyway try this to get the sum of time in hours or minutes.

    Dim FirstIn As String = CDate(dtp1.value.date).ToString("HH:mm") 'try with or without cdate.
    Dim FirstOut As String = CDate(dtp2.value.date).ToString("HH:mm") 'try with or without cdate.
    
    Dim elapsedTime As TimeSpan = DateTime.Parse(FirstOut).Subtract(DateTime.Parse(FirstIn))
    Dim elapsedMinutesText As String = elapsedTime.Minutes.ToString()
    Dim elapsedHrsText As String = elapsedTime.Hours.ToString * 60
    Dim totalMinute As String = CInt(elapsedMinutesText) + CInt(elapsedHrsText)
    'then try to isert it to txtbox or message box to see the result.
    'but now you can get the minutes and total hours of it.
    

    Hope this it what you want.