Solved

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

Posted on 2004-04-20
13
603 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: 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!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

632 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