-
Mar 4th, 2021, 05:25 AM
#1
Thread Starter
Junior Member
Extract from table all row between date
Hi,
I need to extract from a table a rows from:
3 to 6 months
over 12 months
I have done the queries but did not work:
1)SELECT data_pick FROM table WHERE data <=NOW()-INTERVAL 3 month AND 6 month;
2)SELECT data_pick FROM table WHERE data <=NOW() > 12 month;
Thanks in advance.
-
Mar 4th, 2021, 06:13 AM
#2
Re: Extract from table all row between date
Wrong Forum. This belongs at Database
To your Question: Which DBMS?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Mar 4th, 2021, 06:29 AM
#3
Re: Extract from table all row between date
Originally Posted by hamon
I need to extract from a table a rows from:
3 to 6 months
over 12 months
You can almost certainly do this with database functions, but perhaps the quickest way is to have your Application work out the dates involved and run the queries with those dates in them:
Code:
' 3..6 months
dtFrom = DateAdd( "m", -6, Today() )
dtTo = DateAdd( "m", -3, Today() )
sSQL = "select a, b, c from table1 where value between " _
& Format$( dtFrom, "'yyyy-mm-dd'" ) _
& " and " _
& Format$( dtTo, "'yyyy-mm-dd'" ) _
& " order by value"
' Older than 12 months
dtTo = dtTo = DateAdd( "m", -12, Today() )
sSQL = "select a, b, c from table1 where value < " _
& Format$( dtFrom, "'yyyy-mm-dd'" ) _
& " order by value"
Of course, you should use Parameterised Queries; the above air-code is only an example.
Regards, Phill W.
-
Mar 4th, 2021, 07:25 AM
#4
Re: Extract from table all row between date
Originally Posted by hamon
Hi,
I need to extract from a table a rows from:
3 to 6 months
over 12 months
I have done the queries but did not work:
1)SELECT data_pick FROM table WHERE data <=NOW()-INTERVAL 3 month AND 6 month;
2)SELECT data_pick FROM table WHERE data <=NOW() > 12 month;
Thanks in advance.
First study the syntax for queries.
For your current case you could use the BETWEEN operator:
https://www.w3schools.com/sql/sql_between.asp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|