The length of time drugs can be detected in the body depends on numerous different factors including amount and frequency of use, metabolic rate, body mass, age, overall health and urine pH. For example, heroin and cocaine can only be detected for a few hours after use, but their metabolites can be detected for several days in urine.
Blood tests tend to detect drugs for the lowest length of time; ranging from just a couple of hours to seven days depending on the type of drug. Urine tests detect drugs usually around 24 hours to a couple of days but certain drugs can be detected by urine tests even up to 30 days after the last time they have been taken (especially in the case of prolonged use). When it is important to know whether someone has been clean for a longer period of time, the best way is to test a hair follicle. Drug taking can be detected in the hair for around 90 days for most drugs (with the exception of LSD). This type of drug test is used in child custody battles and other instances where it is imperative to be certain the person has been clean for a sustained length of time.