Reputation: 3276
I need to query SQLite datebase table using the following SQL Statement.
SELECT *
FROM Alarms
WHERE ALARMSTATE IN (0,1,2)
AND ALARMPRIORITY IN (0,1,2,3,4)
AND ALARMGROUP IN (0,1,2,3,4,5,6,7)
AND DateTime(ALARMTIME) BETWEEN datetime("2012-08-02 00:00:00")
AND datetime("2012-08-03 00:00:00")
ORDER BY ALARMTIME DESC
ALARMTIME is of TEXT datatype.
ALARMTIME is displayed in the datagridview as follow "08/03/2012 11:52 AM". Can you use that format for checking like DateTime(ALARMTIME)?
The only problem have with this SQL Statement is that it always returns zero dataset or records. However, SQLite doesn't complain about the syntax.
Upvotes: 1
Views: 7055
Reputation: 122769
Strictly speaking, SQLite doesn't have datetime types for its columns:
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values
The problem here is that the string you're using condition isn't a valid date/time, so it's treated as null:
sqlite> SELECT datetime("2012-08-3 00:00:00");
sqlite> SELECT datetime("2012-08-03 00:00:00");
2012-08-03 00:00:00
(Note 2012-08-03
instead of 2012-08-3
.)
In addition, make sure that the values in your ALARMTIME
are correctly formatted too.
Upvotes: 4