Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-20
13
Medium Priority
?
626 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:Darth_helge
  • 3
  • 3
  • 2
  • +2
13 Comments
 
LVL 17

Assisted Solution

by:mokule
mokule earned 800 total points
ID: 10867394
If You mean inside Your application

variable

ShortDateFormat
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 10867415
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?
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 800 total points
ID: 10867416

   use user defined settings, for example

   unit MyAppContants;
   ....
   const
      Format_ShortDate  = 'dd.mm.yyyy';
      Format_LongDate   = 'dd.mm.yyyy hh:nn:ss'

   procedure MyDateToStr(var InpDate : TDateTime);
   begin
     InpDate = FormatDateTime(Format_ShortDate, InpDate);
   end;

   then from your application use this method ...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:mokule
ID: 10867424

You don't have to change anything in Windows.
0
 
LVL 2

Assisted Solution

by:Ratje
Ratje earned 400 total points
ID: 10867434
Setting and restoring shortdateformat ( and changing separator ) example

var
  Dtscheiding : Char ;
  Dtformat : String [20] ;

  Dtformat        := shortDateFormat ;            // oldformat
  DtSepar    := DateSeparator ;              // oldseparator

  ShortDateFormat := 'dd/mm/yyyy';      
  DateSeparator   := '-';                      


  ShortDateFormat := Dtformat ;                   // restore oldformat
  DateSeparator     := DtSepar ;                 // restore separator

Rat
0
 
LVL 2

Expert Comment

by:Ratje
ID: 10867439
oops Dtscheiding should be DtSepar
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10867468

    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.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10867498
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 ;-)
0
 
LVL 17

Expert Comment

by:mokule
ID: 10867506
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.
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 10867577
sorry.. i was going to give more people points.. but i did wrong
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 10867649
yes, there were many good answers here
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question