[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Calculate no of hrs

Posted on 2013-01-15
12
Medium Priority
?
328 Views
Last Modified: 2013-01-16
Hi Experts,

In my excel file, I have days in format "5d 5h 30m"

where d = day (8.4 hrs a day)

I need to calculate no of hrs in numeric

the above example should calculate

5d 5h 30m = 5*8.4 + 5 + .5 (30/60)
         = 42 + 5 + .5
         = 47.5 hrs
        
therefore value of

5d 5h 30m = 47.5

Please help me creating the formula

Please find attached the excel

Regards,
CalculateDateCount.xls
0
Comment
Question by:tia_kamakshi
[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
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 38779296
I cant see the format you gave in question. can you point out where it is in excel please.
0
 

Author Comment

by:tia_kamakshi
ID: 38779408
applogies,
I attached wrong file previously.

Correct file attached.

Regards,
convertDaysToDaysCount.xls
0
 
LVL 40

Accepted Solution

by:
als315 earned 2000 total points
ID: 38779488
This is case when vba function is very usefl (Alt+F11 to look code)
Public Function Time2Num(A As String) As Double
Dim d As Integer, h As Integer, m As Integer
Dim s As String, i As Integer, l As Integer
Dim t As String
d = 0
h = 0
m = 0
Time2Num = 0
i = Len(A)
Do While i > 0
    t = LCase(Mid(A, i, 1))
    If t <> "m" And t <> "h" And t <> "d" Then Exit Do
    i = i - 1
    s = ""
    Do While Mid(A, i, 1) <> " "
        s = Mid(A, i, 1) & s
        i = i - 1
        If i = 0 Then Exit Do
    Loop
    i = i - 1
    If t = "m" Then Time2Num = Time2Num + CInt(s) / 60
    If t = "h" Then Time2Num = Time2Num + CInt(s)
    If t = "d" Then Time2Num = Time2Num + CInt(s) * 8.4
Loop
End Function

Open in new window

convertDaysToDaysCount.xls
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:tia_kamakshi
ID: 38779536
Many Many Thanks
0
 
LVL 23

Expert Comment

by:NBVC
ID: 38779537
Here might be a formula alternative:

in B3:

=IFERROR(LEFT("  "&A3,FIND("d","  "&A3)-1)*8.4,0)+IFERROR(MID(" "&A3,FIND("h"," "&A3)-2,2),0)+IFERROR(MID(" "&A3,FIND("m"," "&A3)-2,2)/60,0)

copied down
0
 
LVL 24

Expert Comment

by:Steve
ID: 38779712
you can use just this formula:

=SUM(MID(0&A1&"00000",FIND({"d","h","m"},A1&"xdhm")-1,2)/{0.119048,1,60})
0
 
LVL 23

Expert Comment

by:NBVC
ID: 38779793
As written that formula doesn't work for 3 digit days as per the sample workbook provided.... and it gives #VALUE! error for cells with no days defined...
0
 
LVL 24

Expert Comment

by:Steve
ID: 38779843
Ah, didn't open the file to see the variants for the conversion...

The following will do all except the 3 digit day... which would take some other work.
=SUM(MID(0&A6&"00000",FIND({"d","h","m"},A6&"xxdhm")-1,2)/{0.119047619047619,1,60})
0
 
LVL 23

Expert Comment

by:NBVC
ID: 38779937
Perhaps with the extra work....?

=SUM(MID("00"&SUBSTITUTE(A3," ","  ")&"00000",FIND({"d","h","m"},SUBSTITUTE(A3," ","  ")&"xxxdhm")-1,3)/{0.119047619047619,1,60})

but, there are many ways to skin it as we proved...
0
 
LVL 24

Expert Comment

by:Steve
ID: 38780066
Looks about right NB :)
Nice:)
0
 

Author Comment

by:tia_kamakshi
ID: 38782532
Many Thanks all.

als315 worked for me and created a function.

I learned new thing.

Regards,
0
 
LVL 23

Expert Comment

by:NBVC
ID: 38782605
No problem tia,

We were just giving you (and others with similar issues, that come across this thread) alternatives.

Thanks for the feedback.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

649 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