Subtract text with number

how can I subtract 20d 2h 3m in 1h 10m using a formula

      2h 10m - 1h 10m = 1h
     1d  58m - 1h 10m  = 23h 48m

whats the formula for that ?
Georgina CarterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
You cannot subtract text, you text numbers must be changed to proper Date Time number formats.
Rob HensonFinance AnalystCommented:
Well, you can do it with a formula but it would be quite lengthy.

Assuming your times are in separate cells, ie 2h 10m in one cell and 1h 10m in another, for each of the cells you would have to identify the numerical elements, convert them to a constant factor, eg minutes, so that the total value of the cell can be calculated. The cells can then be used within a formula.

So your example "1d  58m - 1h 10m  = 23h 48m"
1d = 24 hours or 1440 minutes
58m = 58 minutes
Total cell value = 1498 minutes

1h = 60 minutes
10m = 10 minutes
Total cell value = 70 minutes

1498 - 70 = 1428

This would then be factored back up to show the right format as required.
Ejgil HedegaardCommented:
A custom function (VBA) can do it.
See sheet.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Rob HensonFinance AnalystCommented:
Agree with Ejgil, a VBA / UDF would be able to do it.

As you do not specify whether there are consistent format to the values, I would suggest that there are 7 different combinations:

Time value contains:
1 - days, hours and minutes
2 - days and hours
3 - days and minutes
4 - hours and minutes
5 - days
6 - hours
7 - minutes

To calculate it in a formula you would effectively need 7 different options to convert from the string to a true time value before calculating.
Martin LissOlder than dirtCommented:
You can use the User Defined Function contained in Module1 of this workbook.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
The difference between Ejgil's solution and mine is that mine considers seconds.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.