如果我可以将该字符串转换为MS Access数据库中的Date,我可以建议,我假设使用VB。我在tx期间创建了这个CustNum,看起来像我想要用于日期计算的TimeStamp,看起来我需要做一些解析,在用CDate转换之前连字符替换,我尝试了几种方法并且到目前为止失败了。最终我想用这个值来计算经过多少时间。
/beta
答案 0 :(得分:1)
你需要先解析那个坏男孩,使其符合MSAccess的期望。如果CustNum的格式发生变化,那么您需要编写一个案例陈述来处理每种格式,但基本上是:
CustNum = Left(CustNum, 10) & " " & Mid(CustNum,12,2) & ":" &_
Mid(CustNum,14,2) & ":" & Mid(CustNum,16,2)
CustNum = CDATE(CustNum)
DaysPassed = DateDiff("d",CustNum, Now()) 'gives the difference in Days
HoursPassed = DateDiff("h",CustNum,Now()) 'gives the difference in hours
MinsPassed = DateDiff("n",CustNum,Now()) 'gives the difference in minutes
希望有所帮助!
答案 1 :(得分:0)
你可以做一些花哨的解析来检索日期和时间:
TimeSpent = FormatHourMinuteDiff(TimeStampStart, TimeStampEnd)
然后,您可以使用以下功能显示使用的时间:
Public Function FormatHourMinuteDiff( _
ByVal datTimeStart As Date, _
ByVal datTimeEnd As Date, _
Optional ByVal strSeparator As String = ":") _
As String
' Returns count of days, hours and minutes of difference
' between datTimeStart and datTimeEnd converted to
' hours and minutes as a signed formatted string
' with an optional choice of time separator.
'
' Example:
' datTimeStart: #10:03#
' datTimeEnd : #20:01#
' returns : 9:58
'
' datTimeStart: #22:13#
' datTimeEnd : #3:45#
' returns : -18:28
'
' 2005-02-05. Cactus Data ApS, CPH.
Const cintMinutesHour As Integer = 60
Dim lngMinutes As Long
Dim strHour As String
Dim strMinute As String
Dim strHourMinute As String
lngMinutes = DateDiff("n", datTimeStart, datTimeEnd)
strHour = CStr(lngMinutes \ cintMinutesHour)
' Add leading zero to minute count when needed.
strMinute = Right("0" & CStr(Abs(lngMinutes) Mod cintMinutesHour), 2)
strHourMinute = strHour & strSeparator & strMinute
FormatHourMinuteDiff = strHourMinute
End Function
功能:
\G