3-5 days, depending on how much water cunsumption and how much you try to sweat the chemicals out of your system. Sweating the impurities out is a faster method. But stay hydrated.
Taken from here Urine Testing Though MDMA is not specifically tested for in the standard 'NIDA-5" drug tests, it is chemically closely enough related to amphetamines that recent MDMA users will test positive in both amphetamines (a common test) and methamphetamines (a somewhat newer and less common test). Because of this, the detection periods for MDMA are going to be very similar to those for amphetamines. Another important point is that many tablets of street ecstasy are not pure MDMA and frequently includes amphetamines (and may also contain DXM, caffeine, MDA, MDE, ephedrine etc). Detection Period Amphetamines are standardly detectable in urine for 24-96 hours after use (72 average). Methamphetamines stay in the system slightly longer, 24-120 hours. Hair Testing MDMA is detectable with hair tests and there are at least two drug testing companies (Psychemedics and Quest Diagnostics) which include it in their standard hair test. Hair tests generally take the most recent 1.5 inches of growth and use those for testing. That provides a detection period of approximately 90 days. If an individual's hair is shorter than 1.5 inches, this detection period will be shorter.