SQL Server and DateTime-Fields

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
formi
Posts: 39
Joined: Thu 17 Apr 2008 13:01

SQL Server and DateTime-Fields

Post by formi » Tue 21 May 2013 19:23

Hi

I have SQL Server 2012 (and D XE2) and a table with DateTime-Fields. If I access this field I get the following results:

in ManagementStudio the SQL SELECT CAST(myDate AS INT) returns0 (as expected)
in ManagementStudio the SQL SELECT myDate returns 1900-01-01 00:00:00.000
in Delphi with a TMsTable myTable.FieldByName('myDate').AsDateTime Returns 2 (why??)

I redevelop an old BDE-application, and in BDE "AsDateTime" was 0 and "AsString" 31.12.1899

Can you please give me some explanations why I get other values? Thanks, Peter

AndreyZ

Re: SQL Server and DateTime-Fields

Post by AndreyZ » Wed 22 May 2013 08:45

Hello,

In Delphi, the value 2 is the correct value for the date 1/1/1900. You can check this using the following code:

Code: Select all

var
  dt: double;
begin
  dt := 2;
  ShowMessage(DateTimeToStr(dt));
end;
For more information, please read the following article: http://docs.embarcadero.com/products/ra ... eTime.html

formi
Posts: 39
Joined: Thu 17 Apr 2008 13:01

Re: SQL Server and DateTime-Fields

Post by formi » Wed 22 May 2013 10:39

Thanks for your information. I see now the difference: in MS SQL the value 0 is 1.1.1900, in Delphi it's 30.12.1899.

AndreyZ

Re: SQL Server and DateTime-Fields

Post by AndreyZ » Wed 22 May 2013 10:47

I am glad to help. If any other questions come up, please contact us.

Post Reply