Problem with dates and TdaCriteria
Using Delphi 7 and 10.06 Professional
I'm using the TdaSQLBuilder function to create a search criteria. This
function takes the following parameters: table, field, operator and value. I
have been able to use this successfully to access my Paradox tables. The
problem I have is when I want to search on a date field. I have tried
putting a date in the "value" parameter but it either doesn't do anything or
I get an access violation. What format should the date be in when I add it
as a criteria ? DD/MM/YYYY or YYYY-MM-DD etc ?
Ian Munro
I'm using the TdaSQLBuilder function to create a search criteria. This
function takes the following parameters: table, field, operator and value. I
have been able to use this successfully to access my Paradox tables. The
problem I have is when I want to search on a date field. I have tried
putting a date in the "value" parameter but it either doesn't do anything or
I get an access violation. What format should the date be in when I add it
as a criteria ? DD/MM/YYYY or YYYY-MM-DD etc ?
Ian Munro
This discussion has been closed.
Comments
Tech Tip: Date formats used by DADE
-------------------------------------------------
DADE handles in two phases:
1. User entry
This occurs when the user specifies a date using the Query tools or the
AutoSearch dialog. DADE converts the date string entered by the user into a
Delphi TDateTime value. The string entered by the user is converted using
Delphi's StrToDateTime. By default Delphi's StrToDateTime relies on the date
formatting variables for the current windows locale. These can be overridden
by the developer. See Delphi online help for StrToDateTime for more
information.
2. SQL submitted to the server
When generating the SQL to be submitted to the database server, DADE
converts the TDateTime value from number 1 above, to a string using the
Delphi's FormatDateTime function. The format string used to convert the
TDateTime is specified by the TdaSession.GetSearchCriteriaDateFormat and
TdaSession.GetSearchCriteriaTimeFormat functions. These are virtual methods
which may be overridden by descendant TdaSession classes.
Below are the default values returned.
{------------------------------------------------------------------------------}
{ TdaSession.GetSearchCriteriaDateFormat }
function TdaSession.GetSearchCriteriaDateFormat(aDatabaseType:
TppDatabaseType; const aDatabaseName: String): String;
begin
{return a format usable by FormatDate}
case aDatabaseType of
dtMSAccess:
Result := 'YYYY-MM-DD';
dtMSSQLServer, dtSybaseASA, dtSybaseASE, dtOracle:
Result := 'YYYY/MM/DD';
dtAdvantage:
Result := 'YYYY-MM-DD';
else
Result := 'MM/DD/YYYY';
end;
end; {function, GetSearchCriteriaDateFormat}
{------------------------------------------------------------------------------}
{ TdaSession.GetSearchCriteriaTimeFormat }
function TdaSession.GetSearchCriteriaTimeFormat(aDatabaseType:
TppDatabaseType; const aDatabaseName: String): String;
begin
{return a format usable by FormatDateTime}
case aDatabaseType of
dtMSAccess:
Result := 'HH::MM::SS';
else
Result := 'HH:MM:SS';
end;
end; {function, GetSearchCriteriaTimeFormat}
Note: DADE augments the above with additional formatting delimiters for
Oracle and MSAccess. See TdaSQL.ResolveCriteria located in
RBuilder\Source\daSQL.pas for more information.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com