0
I am in need of a help with SQL. I need to do a query that returns a history of the current date up to 7 days behind. Could someone please help me?
0
I am in need of a help with SQL. I need to do a query that returns a history of the current date up to 7 days behind. Could someone please help me?
8
If you want to search from the current date, you do not need to enter any date variable. Mysql is smart :), and is able to account for when it is seven days in the past.
SELECT *
FROM tabela
WHERE
data BETWEEN CURRENT_DATE()-7 AND CURRENT_DATE()
BETWEEN
returns what is between these dates.
CURRENT_DATE()
returns the current date.
CURRENT_DATE()-7
returns the current date, minus seven days.
References:
In SQL Server the function for data works like this:
SELECT GETDATE()
Current Date less 7 days:
SELECT DATEADD(dd, -7, GETDATE())
As long as it’s Mysql @Brunão is using.
Exactly I hadn’t thought of that
Thank you very much Otto.... I am using SQL Server...
Any idea how to do this by sending the parameters via Java?
If you will do in the query no matter the programming language you are using Right ?
Browser other questions tagged sql sql-server query historical
You are not signed in. Login or sign up in order to post.
What have you achieved so far? Show us the query you tried.
– Caffé
Take advantage and account which database you are using.
– Caffé