Ideally, you should apply within the 30 days before your intended date of travelling to Singapore.

As for the e-visa, the processing time is about 24 to 72 hours, while it can take longer in certain cases.