I need some help just setting up an equation for this problem, I cannot figure it out.

One train travels from A to B at 19mph. A second train travels from B to A at 21 mph.
One hour before the trains pass each other, how far apart are they?

say the distance from A to B is d

then the distance between trains is
x = d - 19 t - 21 t = d - 40 t

when they pass
d = 19 t + 21 t = 40 tpass

so
x = 40 t pass - 40 t = 40 (tpass -t)

so if tpass - t = 1
then
x = 40