Let W denote the total amount of work which should be done. Then the first person is doing per hour and the second person is doing per hour.

Let t denote the working time (in hours!) of the second person. Then the first person works only (t - 2) hours. Therefore the complete work is done:

Divide by W, expand the brackets and collect like terms:

Since your question asks"...how many hours will it take them working together?"the answer is 4 hours.