Completing requirements for PhD programs years after undergraduate degree
There isn't any issue about time (or age, in most places). If you attend an accredited university for your coursework and get grades like any other student then you should be fine, provided that they will provide a transcript of what you have done when you apply later to a degree program.
But doing online courses or unaccredited work is much chancier and you would then need some other way to assure the new institution that you have the required background.
But ask the registrar of the place where you will take courses about such things (grades, transcripts) to be sure.
It is also very advantageous if you make a positive impression on the faculty giving those courses, since your original professors may not remember much about you and you will want letters of recommendation.