mysqldelphidatefiredac

Filtering Dates in FireDac TTable


I'm having a problem using TTable in FireDac to filter on a date field.

The database in MySQL/InnoDB. The field is of type Date.

The code I am using to set the filter is

Filter := 'date = ' + QuotedStr(FormatDateTime('mm/dd/yyyy', Date));
Filtered := True; 

Every time I either get an error when setting the filter: "EConvertError with message 'Could not parse SQL TimeStamp string'" or the filter fails to find any records.

The above format is for my current regional settings. I've also tried 'yyyy-mm-dd'. And I've tried both both with and without quotes.


Solution

  • So, I spend three hours on this and immediately after I ask the question I find an answer. Use Preprocessor Commands:

    Filter := 'date = {d ' + (FormatDateTime('yyyy-mm-dd', Date))+'}';