42 weeks. Generally doctors do not like to let pregnancies go beyond 42 weeks because the risk of stillbirth starts to go up.
No late limit. The C-section can be performed anytime after 39 completed weeks. Generally, pregnancies that go past the due date are at higher risk for complications. Beyond 41 weeks, the pregnancy should be monitored twice weekly with a test for fetal well being. 42 weeks is really pushing the limits and delivery would be recommended beyond this point.