You need to determine the *specific* transmission code for both trucks. This code is usually found on a tag on the transmission itself. Then, you can compare them. Even if the codes are similar, there might be subtle differences that could prevent a successful fit. You should also verify the transfer case compatibility if it's a 4x4.
In short, don't assume compatibility. Research the transmission codes and consult a repair manual or a parts professional before attempting the swap.