I am pulling data that contains two columns with dates. I only want to return rows of data where date one, last_update occurred within 7 days of date two, program_end_day.
I have tried several variations of the following but this returns rows where last_update occurred years before the program_end_day
and last_updated >= DATEADD(DAY, 7, program_end_day)
What I expect to be returned are rows in which the last_updated date is equal to program_end_day or within 7 days of program_end_day. Something like
| program_end_day | last_updated |
|---|---|
| 2024-3-13 | 2024-3-15 |
| 2024-3-20 | 2024-3-26 |
I have found answers to similar questions but instead of pulling the date from a column its a date the user inputs manually or using the today variable
>Solution :
SELECT * FROM PulledData
WHERE last_updated BETWEEN
program_end_day
AND
DATE_ADD(program_end_day, INTERVAL 7 DAY)