Assuming that you have the Start Date, the Start Day of the Week, and the number of days in the month, you can use this formula:
IF(OR(AND(Number of Days=31, Start Day=0),AND(Number of Days=31, Start Day=5), AND(Number of Days=31, Start Day=6), AND(Number of Days=30, Start Day=0), AND(Number of Days=30, Start Day=6)), 5, 4)