DateDif - Calculating Days and Hours

aziz rasul

Active member
Local time
Today, 19:18
Joined
Jun 26, 2000
Messages
1,935
I have the following code: -

Code:
    Dim StartTime As Date
    Dim FinishTime As Date
    Dim TotalTime As Date

    StartTime = Now

    some processing code
        
    FinishTime = Now

    TotalTime = FinishTime - StartTime

Normally the processing time is under 24 hours. However I have a process that can take over 2 days. How can I amend the code so that I would have say

2 days, 4 hours and 20 minutes

or something similar?
 
Hi -

Give this a try:

Code:
Public Function ddhhnn_diff(dtein As Date, dteout As Date) As String

're: http://www.access-programmers.co.uk/forums/showthread.php?t=183059
'*******************************************
'Purpose:   Returns DateDiff as dd:hh:nn
'Coded by:  raskew
'Input:     From debug (immediate) window:
'           1) ? ddhhnn_diff(#01/01/2009 12:30:00#, #01/02/2009 16:36:30#))
'Output:    1) 01:04:06
'*******************************************
Dim x As Integer
   x = DateDiff("n", dtein, dteout)
   ddhhnn_diff = Format(x \ 1440, "00") & ":" & Format((x Mod 1440) \ 60, "00") & ":" & Format(x Mod 60, "00")

End Function

HTH - Bob
 
Thanks Bob. That worked.
 

Users who are viewing this thread

Back
Top Bottom