Search code examples
stringvbaexceldate-conversion

VBA - convert to date


I have one more time a problem:

I want to convert from Strings to dates in VBA

The Strings look like: YYYY-DD-MM

The date should be like: DD.MM.YYYY

I know, normally you do this with the method cdate(), but it doesn't work here. I think it's because the structure of the string is bad to convert.

thanks for your help

InformatikBabo


Solution

  • Sub Main()
    
        Dim strDate As String
        strDate = "2013-06-11"
    
        Debug.Print "Original Date: ", strDate
        Debug.Print "CDate() Conversion: ", CDate(strDate)
        Debug.Print "Format() as String: ", Format(strDate, "DD.MM.YYYY")
    
    End Sub
    

    and the Immediate Window shows

    enter image description here