The World Federation One Stop Fiqh

Ruling 358

If a person is certain that the time for prayers has set in and he makes the intention of performing an obligatory ghusl, and afterwards he realises that actually he performed ghusl before the time for prayers had set in, his ghusl is valid.