convert decimal part days to hours

Chintsapete

Registered User.
Local time
Today, 12:22
Joined
Jun 15, 2012
Messages
137
I have a query result for example = 2.19 days worked. The result of cumulated hours divided by 8 (hours in the workday). What I want to do is take the .19 and multiply it by 8 (hours in the workday) and I would have the result in actual hours which is what I need. Or of course if there is a way to display that into 2 days and 1.52 hours Rounded up to quarters would be even better.
But with spending hours looking through forums I didn't find a way to just work with the decimals right of the dot. Trim, format, Len didn't work for me, they all give me funny result.
Can anyone point me I the right direction please.
Thanks Pete
 
You have so many options,
Code:
? Right("2.19", InStr("2.19", "."))
19

? Mid("2.19", InStr("2.19", ".")+1)
19

? 2.19 - Int(2.19)
 0.19
 
Thanks pr2-eugin

I only started with VBA, thanks of a lot of help from the forum very recently. I put it together like below:
Code:
Public Function fnHours(SumOfDaysWorked _
                            )
                          Dim Hours
                          Dim PartDay
                      
                              Hours = 8
                              PartDay = [SumOfDaysWorked] - Int([SumOfDaysWorked])
                           
                            fnHours = Hours * PartDay
                            
                            End Function


I'm aware of the hours = 8 is not great, but since I only use it for a few weeks a year it should suffice. I still need to do the homework with your formulas to understand them, but it seems to work.

Thanks a lot for your time, I appreciate it.
 
Do you use Military Time (100 minutes per hour)?
 
does the decimal not just work itself when multiplying by 24...
2.5 days
= 2* 24 + .5 * 24
= 48 + 12
= 60 hrs

Code:
fnHours = SumOfDaysWorked * 24
 
Hmm maybe I need to know more about the parameter's value and what it represents...
 
Thanks guys for the replies. I don't use military hours, but for my season dudes working they do a few tasks each day with fixed hours, which I added up over the week and divided by 8 hours in a normal working day. This gives me the for example the 3.19 days worked. I transfer that into my payroll manually, but my payroll is set up for days and hours, so the decimal result I get from my calculations needed to be re-converted.
The solution I posted above works perfect, although I did add another function for the days as below.
Code:
Public Function fnHours(SumOfDaysWorked _
                            )
                          Dim Hours
                          Dim PartDay
                      
                              Hours = 8
                              PartDay = [SumOfDaysWorked] - Int([SumOfDaysWorked])
                           
                            fnHours = Hours * PartDay
                            
                            End Function

Public Function fnDays(SumOfDaysWorked _
                        )
                        Dim Days
                        
                        Days = Int([SumOfDaysWorked])
                        
                        fnDays = Days
                        End Function

The result:
EmployeeName DaysWorked = 3 HoursWorked = 1.75

I'm sure there is a simpler way writing these functions, but as I said earlier, I'm complete rookie in VBA. And this is what I needed for my purpose.
Your suggestion Dan didn't quite work for my purpose as you realized yourself I think not knowing where I came from with my numbers.
Thanks for your time all you guys and enjoy the festive.
PS: If someone is bored out there, and wants to write the code properly for someone else who might have the same problem, please do, then at least my poor code is not going to pollute the world of coding. :o:)
 
Do you use Military Time (100 minutes per hour)?

Nonsense. Military time has sixty minutes in an hour. It is simply written in 24 hour time without a separator.
 

Users who are viewing this thread

Back
Top Bottom