CORRECTION:
As Steve Greir points out below you can do the extension of stay application from 30-45 days before the day your permission to stay expires up to the day it expires.
ORIGINAL COMMENT (requirements below only hold for the application for a Non-O visa inside Thailand):
@M ****
Do it as early as you can, some offices require you have at least 15 days remaining on permission to stay (others 20 days).
Always do things early. Problems can often be solved with time. Without time things become a problem. ;-)