Link to home
Start Free TrialLog in
Avatar of Mike Satterfield
Mike Satterfield

asked on

Looking for an Excel formula to convert time.

I have a report in excel where the total time is written like so:

100d2h54min29s

I was wondering / hoping someone had a formala to confert that data into a straight number of seconds.

IE:

8650469

Thank you,
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

It would be easy to do that with the help of VBA. Are you open to a VBA solution to have a User Defined Function which you can either use in macros or on the worksheet itself as a regular formula?
Avatar of Mike Satterfield
Mike Satterfield

ASKER

Yes i would be open to that.
What happens to the string if an element is zero?

Does it still show in the string, eg 0h or will that element be omitted?
Try this formula, where string is in A4:

=MID(A4,1,FIND("d",A4,1)-1)*86400+MID(A4,FIND("d",A4,1)+1,FIND("h",A4,1)-FIND("d",A4,1)-1)*3600+MID(A4,FIND("h",A4,1)+1,FIND("m",A4,1)-FIND("h",A4,1)-1)*60+MID(A4,FIND("m",A4,1)+3,2)*1

Assumes elements with zero value will still be included.
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Assuming that d, min and h are all present, you may use:
=86400*(LEFT(A2,SEARCH("d",A2)-1)+SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(MID(A2,SEARCH("d",A2)+1,99),"h",":"),"min",":"),"s",""))

Open in new window

@byundt - nice logic, convert the days and then convert the remaining string into a proper time stamp.
Thank everyone who participated!

I really appreciate the assistance.
Glad to help, can you confirm whether the string will have all elements even if 0 value?

If the elements will still be included, even if zero, then the formula options would work. If not then you are right to choose the UDF option from Neeraj as the formula options would not work or would give incorrect result in those cases.
You're welcome Mike! Glad I could help.