You are not logged in.
Pages: 1
i use Filter Data type String , Integer in mORMot it's no problem.
but i Filter type Date Data not found.
how to use Filter Date Data. thank you so much.
SQL Server DB
Offline
The following works perfectly for SQLite for me, but since mORMot persists datetime fields as ISO8601 I think it most probably also works with MS SQL.
function GetDateTimeRangeFilteringSqlClause(const aFieldName: String; const aStartTime, aEndTime:
TDateTime): String;
begin
Result := Result + FormatUTF8('(%>="%" AND %<="%")',
[aFieldName, DateToIso8601(aStartTime, True), aFieldName, DateTimeToIso8601(aEndTime, True)]);
end;
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Not exactly...
For safety and performance, always use bound parameters for your query, and DateTimeToSQL(), via e.g.
result := result + FormatUTF8(' %>? and %<=?', [aFieldName, aFieldName], [DateTimeToSQL(aStartTime), DateTimeToSQL(aEndTime)]);
or
result := FormatUTF8('% %>? and %<=?', [result, aFieldName, aFieldName], [DateTimeToSQL(aStartTime), DateTimeToSQL(aEndTime)]);
See the documentation at https://synopse.info/files/html/Synopse … ml#TITL_36
Offline
Oh yes, did a code search and found that I also use that approach you illustrated
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Thank you so much
Offline
Pages: 1