Custom Query: Get last weekday (Sunday) of month in timestamp

Custom Query: Get last weekday (Sunday) of month in timestamp

Hello,

I need to select the last sunday of the month of a given timestamp:
Example:
- Input: '1991-03-12'
- Output: '1991-03-31'
How can I do this?

Regards,
Sven