Solved

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

Posted on 2004-04-20
13
583 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
Comment Utility
If You mean inside Your application

variable

ShortDateFormat
0
 
LVL 5

Author Comment

by:Darth_helge
Comment Utility
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
Comment Utility

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

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

Assisted Solution

by:Ratje
Ratje earned 100 total points
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Expert Comment

by:Ratje
Comment Utility
oops Dtscheiding should be DtSepar
0
 
LVL 12

Expert Comment

by:Ivanov_G
Comment Utility

    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
Comment Utility
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
Comment Utility
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
Comment Utility
sorry.. i was going to give more people points.. but i did wrong
0
 
LVL 5

Author Comment

by:Darth_helge
Comment Utility
yes, there were many good answers here
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

16 Experts available now in Live!

Get 1:1 Help Now