Try like this:
Dim dt As DateTime = (New DateTime()).AddDays(0.559861111)
It is working for me. It returns:
13:26:12 from 0.559861111
Question
I was trying to read an Excel file to a VB.NET application. When reading the Excel file, the column time in the file does not return a time format, rather it returns an integer, e.g.:
17:14:04 --> 0.718101852
13:26:12 --> 0.559861111
7:26:29 --> 0.31005787
How can I turn these numbers back to time format?
Please Help me thanks
Solution 2
Try like this:
Dim dt As DateTime = (New DateTime()).AddDays(0.559861111)
It is working for me. It returns:
13:26:12 from 0.559861111
OTHER TIPS
Dim dttm As DateTime = (New DateTime()).AddDays(worksheet.Cells(2, 3))
TextBox1.Text = ddtm.toString()
My excel worksheet is like this:
And my code is like this, It is works well.
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim DateVal As String, TimeVal As Double, myTime as Date
On Error GoTo OpenCSVfileError
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(FileName)
xlWorkSheet = xlWorkBook.ActiveSheet
Dim xRng As Excel.Range
xRng = CType(xlWorkSheet.Cells(2, 1), Excel.Range)
DateVal = xRng.Value.ToString
myTime = CDate(DateVal)
xRng = CType(xlWorkSheet.Cells(2, 2), Excel.Range)
TimeVal = CDbl(xRng.Value.ToString)
myTime = myTime.AddDays(TimeVal)
OpenCSVfileError:
xlWorkBook.Close()
xlApp.Quit()