怎么把字符串转化成日期
请大家帮帮忙,看一下,怎么把字符串“20070603”转化成时间的类型date,我当时为了方便,把时间转化成字符串来存储,现在麻烦了,因为我要用datediff 这个函数来计算两个时间之间的间隔,必须要求都是date类型的。
我用过cdate,format(string,“YYYYMMDD”)来转化成时间,发现都不行。现在急死我了。
'''''''''''(1)方法1''''''''''''
Private Function ConvStringToDate(DateExpression As String) As Date
Dim Year As String
Dim Month As String
Dim Day As String
Year = Left$(DateExpression, 4)
Month = Mid$(DateExpression, 5, 2)
Day = Right$(DateExpression, 2)
ConvStringToDate = DateTime.DateSerial(Year, Month, Day)
End Function
'''''''''''''(2)方法二'''''''''''''
Private Function ConvStringToDate(DateExpression As String) As Date
ConvStringToDate = DateTime.DateSerial(Left$(DateExpression, 4), Mid$(DateExpression, 5, 2), Right$(DateExpression, 2))
End Function