Convert double variable type into Days, Hours and Minutes

jag108

Active Member
Joined
May 14, 2002
Messages
433
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Good Day All,

Trying to convert a double type value into Days, Hours, Minutes. This is monitoring server up times, I keep getting a overflow error.

VBA Code:
Function ConvertTime()
Dim seconds As Double
seconds = 1493674.94405120

       ConvSec = seconds Mod 60
       ConvMin = (seconds Mod 3600) \ 60  ' [COLOR=rgb(65, 168, 95)]OK[/COLOR]
       ConvHour = (seconds Mod (3600 * 24)) \ 3600 ' [COLOR=rgb(184, 49, 47)]Fails[/COLOR]
       ConvDays = seconds \ (3600 * 24)
       ConvertTime = ConvDays & " days " & ConvHour & " hours " _
                   & ConvMin & " minutes and " & ConvSec & " seconds"
End Function
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Changing (3600*24) to 86400 cures the problem.

Also, a different method that works (something I tried before I found cure for the error in your method).
VBA Code:
Function ConvertTime()
Dim seconds As Double
seconds = 1493674.9440512
seconds = seconds / 86400
ConvertTime = Format(seconds, "0"" Days ") & Format(seconds, "hh"" Hours ""mm"" Minutes ""ss"" Seconds")
End Function
 
Upvote 0
Changing (3600*24) to 86400 cures the problem.

Also, a different method that works (something I tried before I found cure for the error in your method).
VBA Code:
Function ConvertTime()
Dim seconds As Double
seconds = 1493674.9440512
seconds = seconds / 86400
ConvertTime = Format(seconds, "0"" Days ") & Format(seconds, "hh"" Hours ""mm"" Minutes ""ss"" Seconds")
End Function

Perfect, thank you Sir :)
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top