Can I pray for the past to change certain aspects of life? (Catholic perspective) I'd like to know if according to the Catholic teaching I can pray for the past events that didn't happen?

For example:

If a woman miscarried a child which means the child wasn't baptized and at that moment woman didn't know it was necessary for the child to be baptized in order to get in heaven. And now after some time she gained the knowledge and ask the angel in a prayer go back in time and perform the prayer of baptism over the baby.

Or when some relative dies and after 5 years I gain the knowledge that the person might be in purgatory and maybe I should pray for the person. Can I offer all of my prayers I've done since and pointed them to the moment when the relative died? Will that be added to that soul to the moment of her death or only to the current moment? 

Is this something we can do according to the catholic theology? Or we can only pray for the present situations and is everything bound to the present moment only? I know this can be difficult to research but maybe someone can find something within the tradition.
There is nothing preventing you from praying for anything you'd like, of course; it seems that your question isn't so much &quot;Can we do this?&quot; as &quot;Does it do any good—can it change the past?&quot; And in this case, the standard Catholic answer is &quot;No, unfortunately it can't.&quot;
Aquinas addresses the question in the Summa Theologica, First Part, Question 25, Article 4, titled &quot;Whether God can make the past not to have been?&quot; He considers the possibility, for example, that since God certainly had the power in the past to do or to prevent something, it seems that he should retain that power into the present:

What God could do, He can do now, since His power is not lessened. But God could have effected, before Socrates ran, that he should not run. Therefore, when he has run, God could effect that he did not run.
(Objection 2)

The difficulty Aquinas finds with this is essentially that it would make true the statement that &quot;Socrates did run [since God had to do something about it after the fact] and Socrates did not run [since God prevented it after the fact].&quot; But this is a contradiction:

That the past should not have been implies a contradiction. For as it implies a contradiction to say that Socrates is sitting, and is not sitting, so does it to say that he sat, and did not sit. But to say that he did sit is to say that it happened in the past. To say that he did not sit, is to say that it did not happen. Whence, that the past should not have been, does not come under the scope of divine power.

In other words, anything God could have made to not happen in the past would have to have both happened (so that God had something to prevent) and not happened (because God prevented it). Aquinas believes that contradictions like this are impossible: not because it is a limitation on God's power, but simply because logically impossible things are (by that very fact) not something we can reason logically about:

[A logically impossible event] cannot come under the divine omnipotence, not because of any defect in the power of God, but because it has not the nature of a feasible or possible thing. Therefore, everything that does not imply a contradiction in terms, is numbered amongst those possible things, in respect of which God is called omnipotent: whereas whatever implies contradiction does not come within the scope of divine omnipotence, because it cannot have the aspect of possibility.
(First Part, Question 25, Article 3)

Certainly if God cannot be said to be capable of changing the past, we cannot successfully pray to Him to do it.
As far as your examples, if a child has died without baptism, we certainly commend the child to God in the hope that they will be saved in a way unknown to us; but we cannot go back and get the child baptized. This is a sad thing, sadder than the death of the child perhaps; but it does not prevent God from working in the life of the mother, and this may be the best that can be hoped for.
Similarly, if a relative dies and you believe they are in Purgatory, the right and best thing to do for them is to pray for them in the present moment, as you suggest. Pray that they may soon be released from Purgatory—and incidentally, ask them to pray for you that you may not have to go through that.