Skip to content

Convertir fechaHora a cadena

January 19, 2012

 ‘Funció per transformar format datahora a cadena de text de 14 caràcters
    ‘Format d’entrada                    15/12/2011 9:21:50
    ‘                                  o 15/12/2011 12:20:45
    ‘Format de sortida                   20111215092150 o 20111215122045    
 
    Function dataHoraACadena(ByVal dataEntrada As String) As String

        Dim cadena As String
        Dim any As String
        Dim mes As String
        Dim dia As String
        Dim hora As String
        Dim min As String
        Dim seg As String

        any = Mid(dataEntrada, 7, 4)
        mes = Mid(dataEntrada, 4, 2)
        dia = Mid(dataEntrada, 1, 2)

        If dataEntrada.Length = 18 Then
            hora = Mid(dataEntrada, 12, 1)
            min = Mid(dataEntrada, 14, 2)
            seg = Mid(dataEntrada, 17, 2)
            cadena = any + mes + dia + “0” + hora + min + seg
        ElseIf dataEntrada.Length = 19 Then
            hora = Mid(dataEntrada, 12, 2)
            min = Mid(dataEntrada, 15, 2)
            seg = Mid(dataEntrada, 18, 2)
            cadena = any + mes + dia + hora + min + seg
        End If

        Return cadena

    End Function

From → Datos

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: