Yes, you can leave Thailand on the same day your visa stamp expires, as long as you exit before 11:59 PM on that date. Doing so will prevent you from going into overstay.
The ask:thailand community, consisting of multiple Q/A groups with over 100,000 members, powers this platform. It is not an official government resource. Our members actively contribute to this resource, and while we strive for accuracy, we cannot guarantee its complete reliability. Assistance to travelers is provided as a community service.