Skip to main content
Question

Fetch data between two dates using excel as database

  • 3 January 2023
  • 3 replies
  • 247 views

How can I fetch data between two date ranges using select query?

For eg I want the records that lie in the month of Oct 2022-Dec 2022. I am using below select query :

 

select * from Sheet1$$] where Date] BETWEEN #10/1/2022# AND #12/31/2022# 

 

the query is giving me records of every year for the months of Oct-Dec instead I want the records for just 3 months (Oct,Nov,Dec) of the year 2022.

P.S. - I am using excel as database

3 replies

Userlevel 5
Badge +14

@Abhi25  use this formula 
 

 

Userlevel 7
Badge +13

Hi @Abhi25 ,

 

Try with the following query.

 

SELECT * from [Sheet1$$] where
([Date] BETWEEN '2013-01-03'AND '2013-01-09') OR
([Date] BETWEEN '2013-01-03' AND '2013-01-09') OR
([Date] <= '2013-01-03' AND [Date] >= '2013-01-09')

You have to cover all possibilities. From Date or To Date could be between your date range or the record dates could cover the whole range.

 

Userlevel 5
Badge +9

@Abhi25 ,

Maybe you can try some other filters in order  to identify what causes the incorrect data.

select * from [Sheet1$$] where [Date] BETWEEN #10/01/2022# AND #12/31/2022# 

select * from [Sheet1$$] where [Date] BETWEEN #01/01/2022# AND #12/31/2022# 

select * from [Sheet1$$] where [Date] BETWEEN #10/01/2022# AND #10/31/2022# 

..etc

 

and the above query provided by @Padmakumar 

 

Regards

Reply