# 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?

x
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.
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.
Commented:
A custom function (VBA) can do it.
See sheet.
TimeSubtract.xlsm
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.
Older than dirtCommented:
You can use the User Defined Function contained in Module1 of this workbook.

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

Experts Exchange Solution brought to you by