How to calculate lunar phases?
This can be done with astronomical algorithms that are very complex. Usually some empirical approximations are used that cause a certain degree of accuracy degradation. For most practical cases an accuracy of several hours can be sufficient. However, in the case of complications with conception, a much higher tolerance (up to minutes) may be required.