Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Select between dates

Tags:

sql

sqlite

I am running sqlite to select data between two ranges for a sales report. To select the data from between two dates I use the following statement:

SELECT * FROM test WHERE date BETWEEN "11/1/2011" AND "11/8/2011"; 

This statement grabs all the dates even those outside the criteria. The date format you see entered is in the same format that I get back. I'm not sure what's wrong.

like image 782
Zombian Avatar asked Nov 18 '11 18:11

Zombian


People also ask

How do I select between two dates in SQL?

The SQL BETWEEN OperatorThe BETWEEN operator selects values within a given range. The values can be numbers, text, or dates. The BETWEEN operator is inclusive: begin and end values are included.

How do I select a specific date range in SQL?

SELECT * FROM PERSONAL WHERE BIRTH_DATE_TIME BETWEEN '2001-03-01 11:00:00' AND '2005-03-01 22:00:00';

Can Between be used for dates?

As mentioned above BETWEEN operator can be used along with numeric value, text value, and date.


1 Answers

SQLLite requires dates to be in YYYY-MM-DD format. Since the data in your database and the string in your query isn't in that format, it is probably treating your "dates" as strings.

like image 66
Eric Petroelje Avatar answered Oct 12 '22 13:10

Eric Petroelje