In vitro fertilization clinics have techniques for statistically enhancing your chances of selecting which gender you prefer but it is very expensive and not 100 percent effective. Most of the techniques are based on the idea that male sperm are stronger swimmers than females. You can apply the same technique at home by the female standing in a vertical position for a good while after sex if you want a male. The theory is that the stronger swimmers can overcome gravity and make it to the egg first. That may add a few percentage points to the odds of producing a male but it is far from a sure thing.
As for "when" use a fertility calculator to determine your fertile days.
Most 1st children that are born are male. I notice that among people I know, but it's a roll of dice. I am the idea "let it be, whatever comes" If you do believe in God, you can always pray about it, but God does whatever pleases him. So it's just a mystery of life which for me I like to keep natural.