Solved

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

Posted on 2004-04-20
13
587 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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
 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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