How early in a pregnancy can you do a DNA test on the baby?

12 weeks. At 12 weeks gestation, you can have an amniotomy done to take sloughed skin cells to test for genetic disorders. However, it is not a risk-free procedure, and you should discuss the risks with your obstetrician.
NIPP at 9 wk. There is an expensive but non-invasive form of prenatal testing called by the acronym NIPP(non invasive prenatal paternity) . It requires a sample of mothers blood and some from the designated dad. You can source this on line. The alternatives involving putting a needle up the birth canal or through the abdominal wall to get fetal tissue, or waiting until after the baby is born. .
Starting at 10 weeks. Fetal dna testing to screen for abnormalities can be done as early as 10-12 weeks by chorionic villus sampling(cvs). Cvs is usually done when: prenatal screening is abnormal; maternal age > 35, family history of genetic disease; prior chromosomal abnormalities with pregnancy loss. Or at 15-20 weeks an amniocentesis may be opted for, for the same indications. Discuss the risks with your obgyn.