I’m trying to create a program that watches and searches for any logs within given dates.
How can I load the last 7 days in DATE
format (YYYY-MM-DD) to a string/string list, or via SQL, or Qt/C++.
Currently, I have this SQL command:
SELECT NOW() + INTERVAL -7 DAY
Which displays (for today, "24. 1. 2024") only one value: "2024-01-17".
What I’d like to get is this:
2024-01-24 n 2024-01-23
2024-01-22
2024-01-21
2024-01-20
2024-01-19
2024-01-18
2024-01-17
I know for sure that I’ve basically told SQL to "pick a date from now seven days back", so it’s wrong as it is, but need to edit it so it’ll display 7 different date values for each day.
2
Answers
You can use a recursive cte to get the result you want:
db<>fiddle here
See example. Generate series from date for MySql