# Subtract text with number

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

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

whats the formula for that ?
###### Who is Participating?
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.

Group Finance ManagerCommented:
You cannot subtract text, you text numbers must be changed to proper Date Time number formats.
0
Finance 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.
0
Commented:
A custom function (VBA) can do it.
See sheet.
TimeSubtract.xlsm
1
Finance 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.
0
Older than dirtCommented:
You can use the User Defined Function contained in Module1 of this workbook.

Usage:
=SubtractText(A1,B1)
29090504.xlsm
0

Experts Exchange Solution brought to you by

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

Older than dirtCommented:
The difference between Ejgil's solution and mine is that mine considers seconds.
0
###### 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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.