Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert HH:MM to numbers with decimals

Posted on 2014-12-19
8
Medium Priority
?
120 Views
Last Modified: 2014-12-22
I'm trying to figure out how to convert hh:mm (hours and minutes) to numbers with decimals.  So for example:

01:00 would be 1.0 hours
01:30 would be 1.5 hours
00:45 would be .75 hours

etc., etc., etc.

Is there a formula for this?
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40509378
place this codes in a regular module

Function Convert2Dec(vTime) As Double
Convert2Dec = Val(vTime) + Split(vTime, ":")(1) / 60
End Function


then call the function
Convert2Dec("01:30")
0
 

Author Comment

by:SteveL13
ID: 40509390
I actually want to use it on a form.  So if Field1 is the original value I want to convert then Field2 needs to be the converted value.  

How do I do that?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40509409
me.field2=Convert2Dec(me.field1)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:SteveL13
ID: 40509495
I'm getting an error:

Subscript out of range.

I have this in a module:

Function Convert2Dec(vTime) As Double

    Convert2Dec = Val(vTime) + Split(vTime, ":")(1) / 60
    
End Function

Open in new window


And I have this in the oncurrent event of the form that the two fields are on:

Private Sub Form_Current()

    Me.txtConvertedHrs = Convert2Dec(Me.txtHrVariance)

End Sub

Open in new window

0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40509539
check the value of Me.txtHrVariance

also,  change the function to this

Function Convert2Dec(vTime) As Variant
    If vTime & "" = "" Then Convert2Dec = Null: Exit Function
    If InStr(vTime, ":") = 0 Then Convert2Dec = Null: Exit Function
    Convert2Dec = CDbl(Val(vTime) + Split(vTime, ":")(1) / 60)
   
End Function
0
 

Author Comment

by:SteveL13
ID: 40509607
No more error.  But no results in the field txtConvertedHrs either.

The value in me.txtHrVariance is 0:30  (and the format is Short Time)

I have this in a module:

Function Convert2Dec(vTime) As Variant
     If vTime & "" = "" Then Convert2Dec = Null: Exit Function
     If InStr(vTime, ":") = 0 Then Convert2Dec = Null: Exit Function
     Convert2Dec = CDbl(Val(vTime) + Split(vTime, ":")(1) / 60)
     
 End Function

Open in new window


And I have this in the oncurrentevent of the form:

Private Sub Form_Current()

    Me.txtConvertedHrs = Convert2Dec(Me.txtHrVariance)

End Sub

Open in new window

0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40509647
if it is time, just use

cdbl(Me.txtHrVariance) * 24
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40509648
Me.txtConvertedHrs = cdbl(Me.txtHrVariance) * 24
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question