K
K
krka922019-08-22 11:12:47
Delphi
krka92, 2019-08-22 11:12:47

Why does MS SQL format dates differently?

MS SQL Server 2014
There is a table in which some dates are written in the format:
2017-11-01
There is some code with which I make a data selection (including these dates).
The question is this: if I execute the code on the same machine where the SQL server is installed, then the dates come to me in the format:
01.11.2017
That is, they are converted.
And if I execute the code on another machine, then the dates come in the original format, that is, the
2017-11-01
code is simple. Such an example:

FSQL := 'select f.sdu as StartDate from tableName f';
with Connect.SQLSelect(FSQL) do 
begin
  FLD_DS := Fields.FieldByName('StartDate');
  while not eof do
  begin
    //Операторы
    Next;
  end;
end;

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
auoa16, 2019-08-22
@krka92

If you need to receive in a single format, just pass the culture(third) format to format, for example, for the 11/01/2017 format like this:SELECT FORMAT( GETDATE(), 'd', 'ru-RU');

R
Radjah, 2019-08-22
@Radjah

I used to do something like this:
And further dismantled already means of language.
In the database itself, the field type was "datetime"

Z
zhaar, 2019-08-22
@zhaar

You can also force the locale in the request. At one time, it was convenient to switch to the RU locale when generating HTML files with understandable dates, and then switch back to English.

K
Konstantin Tsvetkov, 2019-08-22
@tsklab

TDateTimeField.DisplayFormat Property .
CONVERT: date and time styles .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question