Getting the Number of Hours (or portions of) between two Times

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to get the # of hours between two time values.

I am using this line of code in my attempts to do so ...
Code:
Me.uf8g_e_minsdev = format(TimeValue(Me.uf8g_apetime) - TimeValue(Me.uf8g_petime), "0.00")

Me.uf8g_apetime = "9:00 PM", and Me.uf8g_petime = "8:30 PM"

The result I get (Me.uf8g_e_minsdev) = 0.02. I am expecting 0.5 (1/2 hour)

Can anyone suggest how I must change my formula to get the desired result.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Maybe
Code:
Me.uf8g_e_minsdev = Format((TimeValue(Me.uf8g_apetime) - TimeValue(Me.uf8g_petime)) [COLOR=#ff0000]* 24[/COLOR], "0.00")
 
Upvote 0
Hello tetra, thank you so much for your help.
I made a change based on your suggestion ...
Code:
Me.uf8g_e_minsdev = format(TimeValue(Me.uf8g_apetime) - TimeValue(Me.uf8g_petime) * 24, "0.00")

But I'm getting unexpected results with it to.
Me.uf8g_apetime = "9:00 PM", and Me.uf8g_petime = "8:30 PM"

The result I get (Me.uf8g_e_minsdev) = -19.63. I am expecting 0.5 (1/2 hour).
It's a bit off.
 
Upvote 0
Ahhhh ... I see! Works like a charm. Thanks!
 
Upvote 0

Forum statistics

Threads
1,216,783
Messages
6,132,682
Members
449,747
Latest member
OldMrsMol

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