I know people say here you can do it online up to the due date. Technically you can but that doesn't mean your immigration will accept/approve it.
I once applied online 4 days before the due date. On the due date I received a rejection notice for it. So I went to the office, Ratchaburi, to do it in person and asked why it was rejected. The officer said I didn't give him enough time to process it and it must be done online 15 days before. So maybe some offices will accept it that close to the due date and some will not.
I usually do it online 14-13 days before the due date with no problem.