Hello,
I am reading in a file which contains the following:
Process started 2023/03/04 22:17:53
Process completed 2023/03/04 22:18:40
Based on this, I wish to be able to place the start/stop times into DateTime, and then subtract start time from stop time, and use this resultant value to list the actual time the process ran.
I have a function which returns a TimeSpan, and this value is then included in a string that will be displayed in MessageBox()
I get the same error message for each determination of stop-start values.
What do I need to do to get this to work?
I am using VS2022, and Net 6.
Thank you for any suggestions.
Code:Public Shared Function CalcTime(Index As Byte) As TimeSpan Dim duration As New TimeSpan . . . Dim startTime As New DateTime(22,17,53) Dim endTime As New DateTime(22,18,40) duration = endTime - startTime 'Subtract start time from end time -> error message: Value of type 'TimeSpan' cannot be converted to 'TimeSpan' 'duration = endTime.Subtract(startTime) 'Subtract start time from end time -> error message: Value of type 'TimeSpan' cannot be converted to 'TimeSpan' Return duration End Function Private Shared Sub Test() Dim duration As TimeSpan Dim durStr As String duration = CalcTime(0) durStr = String.Format("{0:hh\\:mm\\:ss}", duration) Try durStr = String.Format("{0:hh\\:mm\\:ss}", duration) Catch e As FormatException durStr = "Invalid Format" End Try End Sub




Reply With Quote
