Hi all,
I'm using the SQLdb components.
I'm having a problem with a query, I cannot get it to work in the way that I think it should!
I'm attempting to display records in a DBGrid that have a date of a calendar month (January, February etc) but, I think I'm missing something and I don't know what. I'm hoping a fresh pair of eyes will be able to highlight my error.
Code here,
m := month as integer, y := year as integer;
endDate := EndOfAMonth(y, m);
startDate := EncodeDate(y, m, 1);
DecodeDate(startDate, myYear, myMonth, myDay);
sd := IntToStr(y) + '-' + IntToStr(myMonth) + '-' + IntToStr(myDay);
DecodeDate(endDate, myYear, myMonth, myDay);
ed := IntToStr(y) + '-' + IntToStr(myMonth) + '-' + IntToStr(myDay);
ShowMessage(sd);
ShowMessage(ed);
SQLQuery.Close;
SQLQuery.SQL.Text:='SELECT * FROM entry WHERE date BETWEEN ' + sd + ' AND ' + ed;
SQLTransaction.Active := True;
SQLQuery.Open;
The result of this should display only records that have dates within a calendar month. If I substitute "2017-1-31" instead of ed for example for January then the results are correct.
Can someone help me please?