I think the current cutoff is something like 7 years. So if you haven't used it within 7 years you are good (used to be 10, IIRC, and before that lifetime but that's been 20 years or so since that was true, I think). But this is for your background check/security clearance paperwork, I think it's a checkbox like "Have you used marijuana within the last X years? [check yes or no]". If you aren't going for an actual secret (or higher) clearance then the background check is very cursory (check financial records and criminal records, verify education and listed addresses for the reported period).
EDIT: Also, in almost all clearance paperwork you only report back to age 18. So if you're a recent graduate (what this seems to be for) at around age 22-23, and you stopped after high school you likely wouldn't have to report anything at all.
You're confounding the investigation period for a clearance with what they'll accept as far as drug use. Generally speaking Secret clearances investigate back 7 years and Top Secret clearances go back 10. There are, however, questions on the SF-86 that are "ever" questions that ignore these timeline. Regardless you can have used drugs during these periods and tell them as such and there's a chance that they'll grant you the clearance. It's ultimately up to the people adjudicating the clearance and they use a reference guide that's periodically updated to determine this.
Years ago the rule of thumb was that they'd give you a clearance if it'd been 1 year since you used marijuana and 3 years since you used hallucinogens so long as you'd demonstrated a commitment to a drug-free lifestyle since. Anything serious like opioids or alcoholism would require you to have gone to rehab and seriously reformed your life.
In more recent times they seem to have gotten more lenient regarding recent marijuana usage, but I've been out of the industry for a minute so I can't say for sure. What I've always told people is that if you want a cleared job and have done drugs then 1) tell the truth, and if that would get your clearance application denied then 2) wait until it's been long enough so that it won't and clean your act up in the meantime.
> If you aren't going for an actual secret (or higher) clearance
Note that despite how important it sounds, "secret" is not a very high clearance at all. It is the actual lowest classified status - there is "public trust" below that (eg for cops/etc) but that's not an actual classified standard, and FOUO/confidential/etc are not actual classification levels either, just handling guidelines.
Any time you are working on anything military-related you will probably need secret clearance at least. Anyone working with even a basic level of knowledge of military technical or operational capability, or force strength/moment/etc, will be at least Secret.
Anything that you think of as actually being deserving of "secret" most likely falls into the "top secret" category, "secret" is just the completely banal stuff, and you don't have to go far to bump into TS/SCI positions in STEM fields doing military contracting. Any sort of advanced research or development work is probably at least TS if not TS/SCI.
Actual low-level enlisted don't need to be secret (notionally you don't need to know that stuff to "go there and shoot him") but all officers are cleared secret, for example, and I would guess probably NCOs as well (so there's a cap on how high you could be in the military without it). And basically everyone in the civilian world who interacts with the military will be secret.
Federal employees and contractors are subject to regular and random urinalysis.
Until marijuana is legalized at the federal level (which has been passed by the house but is not yet law) you could be terminated for marijuana.
EDIT: Also, in almost all clearance paperwork you only report back to age 18. So if you're a recent graduate (what this seems to be for) at around age 22-23, and you stopped after high school you likely wouldn't have to report anything at all.