I have the following number 34076 which is equivalent to the date 17-04-1993, which function can I use to transform that number to the date indicated, I am working with VBA and that number is retrieved from an excel to a datagridview.
I have the following number 34076 which is equivalent to the date 17-04-1993, which function can I use to transform that number to the date indicated, I am working with VBA and that number is retrieved from an excel to a datagridview.
In the end what I did was a function to transform the string and declare the column in the general type excel
Function Conversion(fecha As String)
Dim sDate As String = fecha
Dim rDate As String
Dim Y As Long, M As Long, D As Long
If Mid(sDate, 3, 1) = 0 And Mid(sDate, 1, 1) = 0 Then
Y = Mid(sDate, 5, 8)
M = Mid(sDate, 3, 2)
D = Mid(sDate, 1, 2)
rDate = "0" & D & "-0" & M & "-" & Y
ElseIf Mid(sDate, 1, 1) = 0 Then
Y = Mid(sDate, 5, 8)
M = Mid(sDate, 3, 2)
D = Mid(sDate, 1, 2)
rDate = "0" & D & "-" & M & "-" & Y
ElseIf Mid(sDate, 3, 1) = 0 Then
Y = Mid(sDate, 5, 8)
M = Mid(sDate, 3, 2)
D = Mid(sDate, 1, 2)
rDate = D & "-0" & M & "-" & Y
ElseIf Mid(sDate, 3, 1) <> 0 And Mid(sDate, 1, 1) <> 0 Then
Y = Mid(sDate, 5, 8)
M = Mid(sDate, 3, 2)
D = Mid(sDate, 1, 2)
rDate = D & "-" & M & "-" & Y
End If
Return rDate
End Function
You have to convert from OLE Automation:
DateTime MyFecha = DateTime.FromOADate(ValorFechaExcel);