I found out the sex of my baby at 19 weeks 3 days. Normally here in the US they schedule an ultrasound between 18-20 weeks to take various measurements of the baby and the tech will usually tell you the sex of the baby. It helps when the baby is in a good position too! Luckily, my baby girl was quite active and flashed her parts a few times, so we were able to find out!
As to the earliest, via ultrasound, I believe is 16 weeks but it's best to wait until you're between 18-26 weeks.