Board index » delphi » Dates...DD.MM.YYYY to MM/DD/YYYY

Dates...DD.MM.YYYY to MM/DD/YYYY

Hello,

How can I change the the date form from DD.MM.YYYY to MM/DD/YYYY? I use
DATE command, and
the change should work in all computers with finnish Windows 98 (the
form is the first one)?
I'm using  Delphi 4 Standard

I did it this way, but there should be the easier way, or is there? (I'm
trying to write it to registry)

Thank you for answering,
Timo Haavisto, KTTP CO. LTD.

Source Follows:

unit Dates;

interface

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

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure Sijoitus;
procedure RAlustus;
procedure RKirjoitus;

var
  Form1: TForm1;
  A: array[0..9] of widechar;
  B,C,D,E,E1,F,G,H,I,J,K :String;
  Kaksi: String;
  Yksi: String;
  Rekisteri: Tregistry;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
sijoitus;
RAlustus;
end;

procedure RAlustus;
begin
Rekisteri:=TRegistry.create;
Rekisteri.RootKey:=HKEY_CURRENT_USER;
if Rekisteri.OpenKey('Software\OwnProg',true) then
   begin
        RKirjoitus;
   end;
end;

procedure RKirjoitus;
begin
     if form1.Tag=0 then
        begin

rekisteri.WriteString('LastDatetry',E+F+'/'+B+C+'/'+H+I+J+K+'
'+timetostr(time));
        end;
     if form1.tag=2 then
        begin

rekisteri.WriteString('LastDatetry',E+'/'+B+c+'/'+G+H+I+J+K+'
'+timetostr(time));
        end;
     rekisteri.CloseKey;
     rekisteri.Free;
end;

Procedure Sijoitus;
begin
     stringtowidechar(datetostr(date),A,12);
     b:=A[0]; {1}
     c:=a[1]; {4}
     d:=a[2];
     e:=a[3];
     f:=a[4]; {.}
     g:=a[5];
     h:=a[6]; {1}
     i:=a[7]; {9}
     j:=a[8]; {9}
     k:=a[9]; {9}
     if F<>'2' then {needed because I need TWO month numbers.}
        begin
        if f='.' then
           begin
             e1:=a[3];
             form1.tag:=2;
             e:='0'+e1;
           end;
        end;
end;

end.

 

Re:Dates...DD.MM.YYYY to MM/DD/YYYY


This a windows property, go to control panel and change the way
the date appear there to the one you want.

Roberto
LOMA Software

Quote
Timo Haavisto wrote:
> Hello,

> How can I change the the date form from DD.MM.YYYY to MM/DD/YYYY? I use
> DATE command, and
> the change should work in all computers with finnish Windows 98 (the
> form is the first one)?
> I'm using  Delphi 4 Standard

> I did it this way, but there should be the easier way, or is there? (I'm
> trying to write it to registry)

> Thank you for answering,
> Timo Haavisto, KTTP CO. LTD.

> Source Follows:

> unit Dates;

> interface

> uses
>   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
> Dialogs,
>   StdCtrls, Registry, ExtCtrls;

> type
>   TForm1 = class(TForm)
>     Timer1: TTimer;
>     procedure Button1Click(Sender: TObject);
>   private
>     { Private declarations }
>   public
>     { Public declarations }
>   end;

> procedure Sijoitus;
> procedure RAlustus;
> procedure RKirjoitus;

> var
>   Form1: TForm1;
>   A: array[0..9] of widechar;
>   B,C,D,E,E1,F,G,H,I,J,K :String;
>   Kaksi: String;
>   Yksi: String;
>   Rekisteri: Tregistry;

> implementation
> {$R *.DFM}

> procedure TForm1.Button1Click(Sender: TObject);
> begin
> sijoitus;
> RAlustus;
> end;

> procedure RAlustus;
> begin
> Rekisteri:=TRegistry.create;
> Rekisteri.RootKey:=HKEY_CURRENT_USER;
> if Rekisteri.OpenKey('Software\OwnProg',true) then
>    begin
>         RKirjoitus;
>    end;
> end;

> procedure RKirjoitus;
> begin
>      if form1.Tag=0 then
>         begin

> rekisteri.WriteString('LastDatetry',E+F+'/'+B+C+'/'+H+I+J+K+'
> '+timetostr(time));
>         end;
>      if form1.tag=2 then
>         begin

> rekisteri.WriteString('LastDatetry',E+'/'+B+c+'/'+G+H+I+J+K+'
> '+timetostr(time));
>         end;
>      rekisteri.CloseKey;
>      rekisteri.Free;
> end;

> Procedure Sijoitus;
> begin
>      stringtowidechar(datetostr(date),A,12);
>      b:=A[0]; {1}
>      c:=a[1]; {4}
>      d:=a[2];
>      e:=a[3];
>      f:=a[4]; {.}
>      g:=a[5];
>      h:=a[6]; {1}
>      i:=a[7]; {9}
>      j:=a[8]; {9}
>      k:=a[9]; {9}
>      if F<>'2' then {needed because I need TWO month numbers.}
>         begin
>         if f='.' then
>            begin
>              e1:=a[3];
>              form1.tag:=2;
>              e:='0'+e1;
>            end;
>         end;
> end;

> end.

Re:Dates...DD.MM.YYYY to MM/DD/YYYY


Quote
Timo Haavisto wrote:

> Hello,

> How can I change the the date form from DD.MM.YYYY to MM/DD/YYYY? I use
> DATE command, and
> the change should work in all computers with finnish Windows 98 (the
> form is the first one)?
> I'm using  Delphi 4 Standard

I usually put these statements in my project .DPR or in MainForm.
They force everybody to have these settings when they are inside
my app, no matter which settings they may have in their Control
Panel settings.

  ShortDateFormat:='d.m.yyyy';  {These Global DateFormat variables will }
  LongDateFormat:='dd.mm.yyyy'; {be valid throughout the prgram}
  DateSeparator:='.';
  ThousandSeparator:='.';
  DecimalSeparator:=',';
  CurrencyDecimals:=2;

I know, some developers don't like this approach. Some say it's wrong
to change the user's own Date,Time,Decimal etc. settings, even
inside one app

Markku Nevalainen

Other Threads