I want o create a dashboard for my API response times and TPS for comparison between multiple timeframes. When ever someone open the dashboard, I want to show a bar chart for yesterday, last month on the same day, and last year on the same day.
Example: 11/24/2025 (yesterday), 10/24/2025 (last month), and 11/24/2024 (last year)
I tried using the following but last month and year doesn't give the correct datetime range:
How can I add an accurate date filter based on when this report is run, 28 day month, 29 day month, 30 day month or 31 day month. I want time range to be more dynamic and automatic.
I'd go for strptime/strftime manipulation.
Did you consider border cases however? How about days like Dec 31st? What would be "last month, same day"? There is no Nov 31st. How about "last year" from Feb 29th on a leap year?