VBA - convert to date

孤街浪徒 提交于 2020-05-14 14:57:07

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/19814978/vba-convert-to-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!