If they get a good look they can tell with certainty at 16 weeks. They can tell with certainty by 14 weeks really. At 12 weeks the shaft begins to fold between the labia for a girl, by 15 weeks it has completely folded in.
That being said, they have to be able to see it all ;-) With our DD they couldn't tell us at her NT Scan and we had to wait 'till 17 weeks. With DS my NT scan was for the last day they'll even do one (13w5d) and my MFM could see very clearly that it was a boy.