Looking to retrieve the date (in YYYY-MM-DD format) for the most recent "Wednesday", "Saturday", or any user-specified day. This date could be from either this week or last week, with the most recent occurrence of that particular day. For instance, if today is January 26th, a Thursday, then the date for last Wednesday would be 2023-01-25, previous Thursday would be 2023-01-19, and last Saturday would be 2023-01-21.
I have explored the use of date-fns
, which includes the startOfWeek
method. However, I encountered an issue with the add
function not accepting negative numbers, preventing me from adding -2, -3, etc. As I am new to TypeScript, any assistance or guidance would be greatly appreciated.