Six weeks. Unless a candidate dies, then it's 4 weeks. That's why Carnahan stayed on the ballot in 2000.
115.363 (3) If the person nominated as the party candidate shall withdraw at or before 5:00 p.m. on whatever day may be fixed by law as the final date for withdrawing as a candidate for the office
115.359 2. Except as provided for in section 115.247, if there is no additional cost for the printing or reprinting of ballots, or if the candidate agrees to pay any printing or reprinting costs, a candidate who has filed or is nominated for an office may, at any time after the time limits set forth in subsection 1 of this section but no later than 5:00 p.m. on the sixth Tuesday before the election, withdraw as a candidate pursuant to a court order, which, except for good cause shown by the election authority in opposition thereto, shall be freely given upon application by the candidate to the circuit court in the county of such candidate’s residence. No withdrawal pursuant to this subsection shall be effective until such candidate files a copy of the court’s order in the office of the official who accepted such candidate’s declaration of candidacy.
You appear to be correct. There is a section that seems to indicate that he would have to withdraw both before and after 5:00 on the same day, but not both. I hate legalese.