transform number to date

0

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.

    
asked by Francisco 27.12.2016 в 16:10
source

2 answers

1

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
    
answered by 28.12.2016 / 19:56
source
1

You have to convert from OLE Automation:

DateTime MyFecha = DateTime.FromOADate(ValorFechaExcel);
    
answered by 27.12.2016 в 18:37