As a rough guide: if you smoke the occasional joint, weed will stay in your system for up to 10 days. If you smoke regularly, up to 45 days and if you smoke constantly, 90 days.
As for being detectable in a drug test, well this depends on the type of drug test. A Urine test will detect up to a month prior, but a blood test will show positive if you’ve smoked any weed in the last 6 months.
Also important to note that marijuana/thc residue is stored in the fat cells, so if you’re skinny or have a high metabolism, the time it takes to leave your system may be reduced.