在我的表中,我有两列包含以下类型的数据:yyyymmdd
和hhmmddxx
- 第一个包含日期,另一个时间精度为 0.01 秒。例如,我有20161102
和17052349
。
我想将其转换为显示某个时刻的单个值并以格式显示dd/mm/yyyy hh:mm:ss.xx
,例如,我想将02/11/2016 17:05:23.49
. 我想我需要使用DateSerial
和TimeSerial
函数,但是有两个问题我不知道如何解决:
像这样的,也许??
? generate_timestamp("20161102","170522349")
给
02/11/2016 17:05:23.49
Function GENERATE_TIMESTAMP(strDate As String, strTime As String) As String
Dim dtDate As Date
Dim dtTime As Date
dtDate = DateSerial(Mid(strDate, 1, 4), Mid(strDate, 5, 2), Mid(strDate, 8, 2))
dtTime = TimeSerial(Mid(strTime, 1, 2), Mid(strTime, 3, 2), Mid(strTime, 6, 2))
GENERATE_TIMESTAMP = FormatDateTime(dtDate, vbShortDate) & " " & _
FormatDateTime(dtTime, vbLongTime) & "." & _
Mid(strTime, 8, 2)
End Function
Run Code Online (Sandbox Code Playgroud)