View Full Version : Date In SQLite Database
Abunasra
05-27-2009, 05:56 PM
Hello Every One.
I have created a SQLite database with a table containing 10 colomns. One of the columns is date. I want to search the database using :
"SELECT * FROM Mydatabe WHERE date BETWEEN 01/01/2008 AND 01/01/2009" , but the search failed.
Could any one please help me with the syntax for date copare in SQLite.
Dermot
05-27-2009, 07:06 PM
Don't store your dates like that, use ISO format (yyyy-mm-dd or yyyymmdd). That is the only date format SQLite understands for SELECT queries.
Abunasra
05-28-2009, 09:36 AM
Thank You very much Dermot for you answer. I Formatted the date as you said. Now if I write the Date directly inside the SQLite.Query I get The result very Fine but when I use a variable which take the formatted date from an input box it says that "No records found" or the like..
I don't Know where the error is ; Details of my work are:
IN project Startup :
db = SQLite.Open("C:\\MyDatabase.db");
SQLite.Query(db, "create table tblBuy(ID integer primary key, name text, date date)");
IN the Button to Search:
--....................
sQuery = "Select * from tblBuy where date between 'myX' and 'myY'";
tBuy = SQLite.QueryToTable(db,sQuery);
myX and myY are two variables containing the formatted date as yyyy-mm-dd. If I replace myX and myY with :
sQuery = "Select * from tblBuy where date between '2009-05-01' and '2009-05-28'";
tBuy = SQLite.QueryToTable(db,sQuery);
--......................
it works fine. Where I am doing error here ?
To be sure that the formatting of date is as requiered I extracted the text into labels and inputs and they were good-formatted.
Please Help me uncover this mystry!
Dermot
05-28-2009, 11:16 AM
You need to look in the help file to learn how to use variables.
sQuery = "Select * from tblBuy where date between '"..myX.."' and '"..myY.."'"
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.