以下のような機能を使用できます。その後:
TimePassed: FormatYearDayHourMinuteSecondDiff(#2016/11/04 11:52:56#, Date())
'TimePassed -> 0 11 12:07:04
それは外部関数Years
を使用しますが、簡単にそれが年を表示しないように変更することができます。
Public Function FormatYearDayHourMinuteSecondDiff(_
ByVal datTimeStart As Date, _
ByVal datTimeEnd As Date, _
Optional ByVal strSeparatorDate As String = " ", _
Optional ByVal strSeparatorTime As String = ":") _
As String
' Returns count of years, days, hours, minutes and seconds of difference
' between datTimeStart and datTimeEnd converted to
' years, days, hours and minutes and seconds as a formatted string
' with an optional choice of date and/or time separator.
'
' Should return correct output for a negative time span but
' this is not fully tested.
'
' Example:
' datTimeStart: #2006-05-24 10:03:02#
' datTimeEnd : #2009-04-17 20:01:18#
' returns : 2 328 09:58:16
'
' 2007-11-06. Cactus Data ApS, CPH.
Const cintSecondsHour As Integer = 60& * 60&
Dim intYears As Integer
Dim intDays As Integer
Dim intSeconds As Integer
Dim intHours As Integer
Dim datTime As Date
Dim strDatePart As String
Dim strTimePart As String
Dim strYDHMS As String
intYears = Years(datTimeStart, datTimeEnd)
datTimeStart = DateAdd("yyyy", intYears, datTimeStart)
intDays = DateDiff("h", datTimeStart, datTimeEnd) \ 24
datTimeStart = DateAdd("d", intDays, datTimeStart)
intHours = DateDiff("h", datTimeStart, datTimeEnd)
datTimeStart = DateAdd("h", intHours, datTimeStart)
intSeconds = DateDiff("s", datTimeStart, datTimeEnd)
' Format year and day part.
strDatePart = CStr(intYears) & strSeparatorDate & CStr(intDays)
datTime = TimeSerial(intHours, 0, intSeconds Mod cintSecondsHour)
' Format hour, minute and second part.
strTimePart = Format(datTime, "hh\" & strSeparatorTime & "nn\" & strSeparatorTime & "ss")
strYDHMS = strDatePart & " " & IIf(datTime < 0, "-", "") & strTimePart
FormatYearDayHourMinuteSecondDiff = strYDHMS
End Function
AFAIKこれはできません。 (DateDiff( "s"、FieldA、now())/ 86400、 "hh:nn") ' – Fionnuala
これは動作します。ありがとう。しかし、なぜdd.hh:nn形式ではうまくいかないのですか? –
秒を変換すると、その日が差異ではなく、その数値によって返された日である数値が得られます。すべての日付は数字です。 – Fionnuala