Date-format on client differs from format on server
Date-format on client differs from format on server
I installed an MS SQL Server 2008 on a Win7-64Bit machine to develop my application. I created a table with a date-field. If I show the fields on that machine it displays the date in the format I want to have (dd.mm.yyyy). If I make the same query on a client I get the fields with format yyyy-dd-mm (with SELECT * FROM myTable).
Where have I to change the format?
Maybe I have to install some SQL-stuff on the client. I didn't install anything (only the SQL-Server on the develop-machine)
Thanks for your help, peter
Where have I to change the format?
Maybe I have to install some SQL-stuff on the client. I didn't install anything (only the SQL-Server on the develop-machine)
Thanks for your help, peter
Hello,
SDAC is a set of non-visual components, and they don't serve for displaying data in VCL visual components. SDAC transfers date values to visual components in the TDateTime format (double). Delphi uses date format that is specified on a client machine. You can use the following code to obtain date in the format you want:Also you can use the ShortDateFormat Delphi variable in the following way:ShortDateFormat is the format string used to convert date value to a short string suitable for editing. For more information, please refer to the Delphi help.
SDAC is a set of non-visual components, and they don't serve for displaying data in VCL visual components. SDAC transfers date values to visual components in the TDateTime format (double). Delphi uses date format that is specified on a client machine. You can use the following code to obtain date in the format you want:
Code: Select all
MSQuery.Open;
ShowMessage(FormatDateTime('dd.mm.yyyy', MSQuery.FieldByName('MyDate').AsDateTime));
Code: Select all
ShortDateFormat := 'dd.mm.yyyy';
MSQuery.Open;
ShowMessage(MSQuery.FieldByName('MyDate').AsString);
Thanks for your answer. I made this but with no success:
- on the pc with SQL Server installed it works fine (I can change the formats)
- in the clients it doesn't work, always same format
As I just sayed I didn't install anything on the clients. Is that ok or have I to install an sql-client? I think it is included in Win7, otherwise I couldn't access anything.
Peter
- on the pc with SQL Server installed it works fine (I can change the formats)
- in the clients it doesn't work, always same format
As I just sayed I didn't install anything on the clients. Is that ok or have I to install an sql-client? I think it is included in Win7, otherwise I couldn't access anything.
Peter
Please try creating a new application with one button on a form, and write the following code:After this check if this application shows the date value in the correct string format on your computer and on a client computer.
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(FormatDateTime('dd.mm.yyyy', now));
end;
Maybe you are using persistent fields and the DisplayFormat property to show dates in the yyyy-dd-mm format. If it's true, please set the DisplayFormat property for your date fields to the blank value.
Also you can try creating another application with the TButton, TMSConnection, TMSQuery, TMSDataSource, and TDBGrid components, and use the following code:This code will force TDBGrid to show date values in the dd.mm.yyyy format regardless of the date format on a client machine. Please check that you are using the same approach in your application.
Also you can try creating another application with the TButton, TMSConnection, TMSQuery, TMSDataSource, and TDBGrid components, and use the following code:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
begin
ShortDateFormat := 'dd.mm.yyyy';
MSConnection1.Server := 'server';
MSConnection1.Database := 'database';
MSConnection1.Username := 'username';
MSConnection1.Password := 'password';
MSConnection1.LoginPrompt := False;
MSQuery1.Connection := MSConnection1;
MSQuery1.SQL.Text := 'select * from MyTable'; // MyTable contains date values
MSDataSource1.DataSet := MSQuery1;
DBGrid1.DataSource := MSDataSource1;
MSQuery1.Open;
end;
I'm sorry, I tried it but its the same result. The main problem is that I have a BDE-application which I convert to MS SQL. In the field-editor of the table there are all fields listed. If I make a select on that table I get (only client) the error "different datatypes for field 'MyDate'. Required "Date", found "WideString". And that is because that format is wrong.
-
- Posts: 1
- Joined: Thu 12 May 2011 14:26