Link to home
Start Free TrialLog in
Avatar of Darth_helge
Darth_helge

asked on

getting/setting the short dateformat in windows by using delphi?

how do i do this?

Our application must have a specific short dateformat.
You can find the dateformat i want to change by clicking control panel-->regional settings-->short dateformat
SOLUTION
Avatar of mokule
mokule
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Darth_helge
Darth_helge

ASKER

but some places in my app i get the date from windows. if this date is in yy.mm.dd, can I just set the ShortDateFormat variable inside my application to the same?
I don't have to change anything in Windows?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

You don't have to change anything in Windows.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oops Dtscheiding should be DtSepar

    Darth_helge, if you get the Date from windows :

    var
        CurrDate : String;
    begin
       CurrDate := MyDateToStr(Now);

    the implementation of MyDateToStr - see my post above. I think you should not change anything in Windows.
Avatar of kretzschmar
just another way

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//get
procedure TForm1.Button1Click(Sender: TObject);
var
  P : array[0..100] of char;
begin
  getLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE,p,SizeOf(p));
  ShowMessage(p);
end;

//set
procedure TForm1.Button2Click(Sender: TObject);
var s : String;
begin
  s := edit1.Text;
  setLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SSHORTDATE,PChar(s));
end;

end.

meikl ;-)
Moreover You don't need set ShortDateFormat.

This variable is set when Your application starts and if variable UpdateFormatSettings is set to True (default setting) it is updated every time user changes Windows setting.

You need to set ShortDateFormat if You store/load dates in a string format and want to convert from string to date and vice versa.
sorry.. i was going to give more people points.. but i did wrong
yes, there were many good answers here