You can have an abdominal ultrasound between 18 to 22 weeks of pregnancy to check the gender of the baby. Factors like the stage of pregnancy and fetus position affect the accuracy of the results.