Page 1 of 1

datetime milliseconds with ado ms-sqlserver

Posted: 13.02.2019, 15:11
by woec
Hi,

in my database application I insert log data into ms sql-server database using ado protocol (ZeosLib 7.2.4 stable, Lazarus 1.8.4 Win 32 and Win64).
Log data contains a datetime timestamp. I encountered the problem, that the millisecond part of the timestamp data is lost at the insert. Only the datetime part down to seconds ist inserted.

Reading the documentation, I found a connection parameter DateTimeWriteFormat to be specified as TZConnection.property. But I could not find any information how to supply the format - it should be according to Delphi standard, but where find this specificaton?

I am also not sure if this parameter, if set correctly, will help to solve my problem.

Can anybody help here?

woec

Re: datetime milliseconds with ado ms-sqlserver

Posted: 14.02.2019, 09:52
by marsupilami
Hello,

you can set DateTimeWriteFormat like this:

Code: Select all

ZConnection.Properties.Add('DateTimeWriteFormat=YYYY-MM-DD HH:NN:SS.ZZZ')
The format specification is the same specification that FormatDateTime uses.

I am not sure if that helps with ADO and MSSQL though because the SQL Server ADO driver should be able to use parameters.

Best regards,

Jan

Re: datetime milliseconds with ado ms-sqlserver

Posted: 15.02.2019, 12:50
by woec
Thank you for the hint.

I tried it, but it does not solve the problem - no change in behavior.

The datetime value is already defined as ftDateTime Parameter type in the TZQuery properties.
Also, I tried different settings for size and precision for this parameter, but also no change.

woec

Re: datetime milliseconds with ado ms-sqlserver

Posted: 17.02.2019, 12:41
by marsupilami
Hello,

which column type do you use in the database?
Best regards,

Jan

Re: datetime milliseconds with ado ms-sqlserver

Posted: 25.02.2019, 08:55
by woec
Hi,

I use the "datetime" datatype for this timestamp in the ms sql-server database.

woec

Re: datetime milliseconds with ado ms-sqlserver

Posted: 11.05.2019, 05:43
by EgonHugeist
please test datetime2
because SQLServer does some roundings using the datetime type