A andyp Member Licensed User Longtime User Dec 23, 2017 #1 Hi I have times in decimal format, where 1.0 = 24hrs. My numbers are all between 0 and 1.0. For example 0.837. I wish to display this in 24hr time format, so 20:05hrs. Excel does this conversion for you...... Multiplying 0.837 * 24 = 20.088 - not quite what I am looking for....... Is there a function, or method to do this conversion? Thank you!
Hi I have times in decimal format, where 1.0 = 24hrs. My numbers are all between 0 and 1.0. For example 0.837. I wish to display this in 24hr time format, so 20:05hrs. Excel does this conversion for you...... Multiplying 0.837 * 24 = 20.088 - not quite what I am looking for....... Is there a function, or method to do this conversion? Thank you!
udg Expert Licensed User Longtime User Dec 23, 2017 #2 Hi, I don't know what Excel does, but maybe this could help: Code: Copy Dim mytime As Double = 0.837 Dim tsec As Double = 1/86400 'seconds on scale 0.0..1.0 Dim temp As Double = mytime / tsec 'mytime in seconds on scale Dim mm1 As Int = temp /60 'mytime in minutes Log(mm1) Dim hr As Int = mm1 / 60 'hours Log(hr) Dim mm As Int = mm1 - (hr*60) 'minutes Log(mm) Upvote 0
Hi, I don't know what Excel does, but maybe this could help: Code: Copy Dim mytime As Double = 0.837 Dim tsec As Double = 1/86400 'seconds on scale 0.0..1.0 Dim temp As Double = mytime / tsec 'mytime in seconds on scale Dim mm1 As Int = temp /60 'mytime in minutes Log(mm1) Dim hr As Int = mm1 / 60 'hours Log(hr) Dim mm As Int = mm1 - (hr*60) 'minutes Log(mm)
A andyp Member Licensed User Longtime User Dec 23, 2017 #3 Hi Peter - Sorry, but that missed what I was after Decimal 1.0 = 24hrs..... Udg - Thank you! Works great. Would you be able to show me how to display this as xx:yy? ie two digits for hours, two for minutes? I can do this Code: Copy Log(hr & ":" & mm & "hrs") But how do I force an Int to be two digits? So instead of say 4:5hrs, it would display 04:05hrs? Thanks again! Upvote 0
Hi Peter - Sorry, but that missed what I was after Decimal 1.0 = 24hrs..... Udg - Thank you! Works great. Would you be able to show me how to display this as xx:yy? ie two digits for hours, two for minutes? I can do this Code: Copy Log(hr & ":" & mm & "hrs") But how do I force an Int to be two digits? So instead of say 4:5hrs, it would display 04:05hrs? Thanks again!
udg Expert Licensed User Longtime User Dec 23, 2017 #4 Code: Copy Log($"$2.0{hr}:$2.0{mm}"$) That should do the trick. Upvote 0
A andyp Member Licensed User Longtime User Dec 23, 2017 #5 Thank you! I was just reading about smart string literal Really nice solution - much better than my backup plan of adding a zero if the number was <= 9 Thanks again! Upvote 0
Thank you! I was just reading about smart string literal Really nice solution - much better than my backup plan of adding a zero if the number was <= 9 Thanks again!
udg Expert Licensed User Longtime User Dec 23, 2017 #6 IMHO, smart string literal is really a powerful tool; keep reading it and experiment a bit. It's well worth your time. Upvote 0
IMHO, smart string literal is really a powerful tool; keep reading it and experiment a bit. It's well worth your time.
M Mahares Expert Licensed User Longtime User Dec 23, 2017 #7 andyp said: Is there a function, or method to do this conversion? Click to expand... udg said: Hi, I don't know what Excel does, but maybe this could help: Click to expand... Here is another alternative pushing the DateUtils: Code: Copy Dim mytime As Double = 0.837 Dim m As Long = mytime*24*DateTime.TicksPerHour Dim p As Period = DateUtils.PeriodBetween(0,m) Log($"$2.0{p.Hours}:$2.0{p.Minutes}:$2.0{p.Seconds}"$) 'displays 20:05:16 You can get rid of seconds if you want Upvote 0
andyp said: Is there a function, or method to do this conversion? Click to expand... udg said: Hi, I don't know what Excel does, but maybe this could help: Click to expand... Here is another alternative pushing the DateUtils: Code: Copy Dim mytime As Double = 0.837 Dim m As Long = mytime*24*DateTime.TicksPerHour Dim p As Period = DateUtils.PeriodBetween(0,m) Log($"$2.0{p.Hours}:$2.0{p.Minutes}:$2.0{p.Seconds}"$) 'displays 20:05:16 You can get rid of seconds if you want