VBA-转换为日期 [英] VBA - convert to date

查看:207
本文介绍了VBA-转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还有一个时间有问题:

I have one more time a problem:

我想从字符串转换为VBA中的日期

I want to convert from Strings to dates in VBA

字符串如下:YYYY-DD-MM

The Strings look like: YYYY-DD-MM

日期应为:DD.MM.YYYY

The date should be like: DD.MM.YYYY

我知道,通常您可以使用cdate()方法执行此操作,但是它在这里不起作用. 我认为是因为字符串的结构不好转换.

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.

感谢您的帮助

InformatikBabo

InformatikBabo

推荐答案

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

随即显示立即窗口

这篇关于VBA-转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆