Most sonographers wouldn't tell you but I have never heard of any legal thing.
Most people find out if they want at 18 weeks scan and those who are that desparate you can have CVS (invasive needle sample) and find out what gender (though it is test for abnormalities).
Parents who are carriers of certain sex linked genetic diseases - do CVS and can terminate.
The sonographer I had said it might not be accurate and often you didn't get a good clear look between the legs anyway even in 4D. They really only measure NF so u/s time is brief. At 12wks baby is barely 6cms or so - as you can imagine the 'accessories' are miniscule.
I know a few mums now on BB whose bub didn't co-operate at 18 -19 week and still don't know what gender.
Bookmarks