Alisha Posted October 5, 2021 Share Posted October 5, 2021 Hello, What's the correct SQL to display information from the past 7 days please? I'm trying to create a List of Data widget. I have used BETWEEN CURRENT_DATE -7 AND CURRENT_DATE but this has given me results from last year as well as this year. When I used >=CURRENT_DATE -7 that gave me today's information as well as the previous 7 days. Many thanks, Alisha Link to comment Share on other sites More sharing options...
Steve Giller Posted October 5, 2021 Share Posted October 5, 2021 @Alisha I think: datetimecol >= CURRENT_DATE() + INTERVAL -7 DAY should do it. You can't just add '7' to a date - how would it know it was days, not months or years? 1 Link to comment Share on other sites More sharing options...
Alisha Posted October 6, 2021 Author Share Posted October 6, 2021 Thanks @Steve Giller. That works but also gives me today's data. Is there a way to not include today please? Link to comment Share on other sites More sharing options...
Steve Giller Posted October 6, 2021 Share Posted October 6, 2021 @Alisha I'm stretching my SQL here, but I would think datetimecol BETWEEN CURRENT_DATE() + INTERVAL -1 DAY AND CURRENT_DATE() + INTERVAL -8 DAY would do it - assuming you want a full week (7 days) of data up to but not including today. You can tweak the -1 and -8 according to the results you get. Link to comment Share on other sites More sharing options...
Alisha Posted October 6, 2021 Author Share Posted October 6, 2021 Thank you @Steve Giller. I have changed it to: BETWEEN CURRENT_DATE() + INTERVAL -7 DAY AND CURRENT_DATE() + INTERVAL -1 DAY Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now