Using Zeos revision 6213 when you try to convert a field of type datetime to string you get only the time, but its not correct as well.
program _Test;
{$apptype console}
uses
SysUtils, ZDataset, ZAbstractRODataset, ZAbstractConnection, ZConnection;
var
c: TZConnection = nil;
q: TZQuery = nil;
sf: TFormatSettings;
begin
sf.DecimalSeparator := '.';
sf.DateSeparator := '-';
sf.TimeSeparator := ':';
sf.ShortDateFormat := 'yyyy/mm/dd';
sf.LongTimeFormat := 'hh:nn:ss';
try
try
c := TZConnection.Create(nil);
q := TZQuery.Create(nil);
c.Protocol := 'odbc_w';
c.Database := 'Driver={ODBC Driver 17 for SQL Server};Server=.\sqlexpress;Database=master';
c.User := 'sa';
c.Password := '1';
c.LoginPrompt := false;
c.UseMetadata := false;
q.Options := [doCalcDefaults];
q.ParamCheck := false;
q.Connection := c;
c.Connect();
q.Sql.Add('set dateformat mdy');
q.Sql.Add('select cast(''2020-01-01 08:30:45'' as datetime)');
q.Open();
Write(q.Fields[0].AsString, #10);//08:01:45
Write(DateTimeToStr(q.Fields[0].AsDateTime, sf), #10);//2020-01-01 08:30:45
q.Close();
c.Disconnect();
finally
q.Free();
c.Free();
end;
except on e: Exception do begin
Write(e.Message, #10);
end end;
end.
Hello Kenny,
i've added a test to see such behavior changes.
Patch done R6222 /testing-7.3
Please update and close if OK.
Happy new year,
Michael