Dear All ,
I am working on a task system and i have to view to the admin how much time taken to end this task
so if i have startDate as 8/9/2019 7:23:13 PM and endDate as 8/8/2019 7:23:13 PM so it should give me 1 day , 0 hour , 0 minutes
Dear All ,
I am working on a task system and i have to view to the admin how much time taken to end this task
so if i have startDate as 8/9/2019 7:23:13 PM and endDate as 8/8/2019 7:23:13 PM so it should give me 1 day , 0 hour , 0 minutes
Start date of Aug 9 and End date Aug 8? Shouldn't those dates be swapped?
Code:Function DHM(dStart As Date, dEnd As Date) As String Dim Dy As Integer, Hr As Integer, Mn As Integer DHM = DateDiff("n", dStart, dEnd) Dy = Int(DHM / 1440) Hr = Int((DHM Mod 1440) / 60) Mn = (DHM Mod 1440) Mod 60 DHM = Dy & " day, " & Hr & " hour, " & Mn & " minutes" End Function
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
On fly (and check brackets). I added some additional brackets and multiplying with 1 too, so the calculation structure in every formula remains same and is easier to follow.
Code:Days = Int(1*(CDbl(EndDate) - CDbl(StartDate))) Hours = Int(24*(1*(CDbl(EndDate) - CDbl(StartDate)) - Int(1*(CDbl(EndDate) - CDbl(StartDate))))) Minutes = Int(60*(24*1*(CDbl(EndDate) - CDbl(StartDate)) - Int(24*1*(CDbl(EndDate) - CDbl(StartDate))))) Seconds = Int(60*(60*24*1*(CDbl(EndDate) - CDbl(StartDate)) - Int(60*24*1*(CDbl(EndDate) - CDbl(StartDate)))))
Worked like a charm , Many thanks !Start date of Aug 9 and End date Aug 8? Shouldn't those dates be swapped?
Code:Function DHM(dStart As Date, dEnd As Date) As String Dim Dy As Integer, Hr As Integer, Mn As Integer DHM = DateDiff("n", dStart, dEnd) Dy = Int(DHM / 1440) Hr = Int((DHM Mod 1440) / 60) Mn = (DHM Mod 1440) Mod 60 DHM = Dy & " day, " & Hr & " hour, " & Mn & " minutes" End Function
And yes you are right time should be swapped
Thanks buddy , I'll keep that in my records tooOn fly (and check brackets). I added some additional brackets and multiplying with 1 too, so the calculation structure in every formula remains same and is easier to follow.
Code:Days = Int(1*(CDbl(EndDate) - CDbl(StartDate))) Hours = Int(24*(1*(CDbl(EndDate) - CDbl(StartDate)) - Int(1*(CDbl(EndDate) - CDbl(StartDate))))) Minutes = Int(60*(24*1*(CDbl(EndDate) - CDbl(StartDate)) - Int(24*1*(CDbl(EndDate) - CDbl(StartDate))))) Seconds = Int(60*(60*24*1*(CDbl(EndDate) - CDbl(StartDate)) - Int(60*24*1*(CDbl(EndDate) - CDbl(StartDate)))))