How do you calculate perihelion or aphelion of a planet?
One uses planetary distance formulas
There are planetary motion formulas for all the planets in our solar system including the moon. The input is the date and time and can yield various coefficients one of which is distance from the Earth.
For example if you computed the distances for the moon over a period over a month and plotted the distance it will resemble the mathematical function Sin. The points of maximum and minimum on this curve correspond to the dates when the moon is in apogee or perigee.
If you use the same approach but for distances in relation to the sun you would be able to determine the date of perihelion or aphelion.