Solved

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

Posted on 2004-04-20
13
584 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 200 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 200 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
 
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 100 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 91
Correct Component for Shopping Cart. 2 95
Create a path if not exists 7 69
Multi-layered image in FireMonkey 9 15
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now