It is generally safe to have sex during pregnancy unless you have specific medical conditions or your healthcare provider advises against it. However, it's important to communicate with your partner and consult your healthcare provider for personalized advice. As for the duration, many couples can continue having sex throughout the entire pregnancy. However, as the due date approaches, certain positions may become uncomfortable or impractical. It's crucial to listen to your body and adjust accordingly. If you experience any pain, bleeding, or other concerns during or after intercourse, contact your healthcare provider immediately.