I have a database/table in SQLITE using the following structure
CREATE TABLE milestones (
ID INT( 10 ) NOT NULL,
Title VARCHAR( 50 ) DEFAULT NULL,
mYear INT( 11 ) NOT NULL,
mMonth INT( 11 ) DEFAULT NULL,
mDay INT( 11 ) DEFAULT NULL,
mText VARCHAR( 2000 ) NOT NULL,
Theme1 VARCHAR( 50 ) DEFAULT NULL,
Theme2 VARCHAR( 50 ) DEFAULT NULL,
ImageURL VARCHAR( 50 ) DEFAULT NULL,
PRIMARY KEY ( ID )
);
我正在利用以下询问,使5个最接近的日期与今天的日期挂钩。
SELECT dtable.ID, dtable.Date
FROM(SELECT ID, date(mYear|| - ||mMonth|| - ||mDay) as Date
FROM milestones
WHERE mMonth IS NOT NULL AND mDay IS NOT NULL AND mMonth ="+varMonth+")AS dtable
ORDER BY ABS("+varDay+"-date(dtable.Date, %d ))
LIMIT 5;
The problems using this query is that I am only getting records with the date format yyyy-mm-dd. If there is any record with 1 digit month or day ( the format yyyy-m-d or yyyy-mm-d or yyyy-m-dd) it doesn t show in the result.
How can I solve this problem without changing the datatype of mMonth or mDay?