Hi All,

1. Should I create a CUSTOM COMPONENT or should I use the WINAPI ??
2. This One gets the points,  How do I change the Machines Regional Settings Shortdateformat ??

I need to display all dates in my app in dd/mm/ccyy format (company standard).

This is fine for any display (ie labels etc..) as I simply call the Delphi function FormatDateTime to format it correctly. E.g. FormatDateTime(‘dd/mm/yyyy’, TDATETIME);…

I however have a problem with the datetimepicker component.
The DateTimePicker uses the machines local shortdateformat to determine how the date is displayed (ie Regional Settings ShortDateFormat).  I tried changing the Delphi global variable ShortDateFormat to “dd/mm/yyyy’ but it had no effect on the components display.  

I’ve kinda look through the windows API functions calls to find something that will allow me to change the machines local shortdateformat, and haven’t really found anything that makes sense to me, something about LOCALES ???. Iam pretty new to using the Win API directly and would greatly appreciate someone pointing me in the right direction ???  The problem here is that if the user changes the machines local shortdateformat while my app is running I will have to trap the system message indicating that it has changed and then change it back to the format I require…. (mmmmm !!, not to kosher).

My another alternative would be to create my own component by inheriting TDATETIMEPICKER and forcing it to display the date as ‘dd/mm/yyyy’.

Perhaps I should consider using both as parts of the solution, changing the machines local shortdateformat using WinAPI functions and create a custom component, but refrain from trapping the system message should the user change the format while my app is running ????


And for the points can some please tell me how or which function to use to change the regional settings shortdateformat !!  pretty please ??

Y2K Issue regarding FormatDateTime, for Delphi 3.0.
NOTE : in delphi 3.0 calling formatdatetime with the machines local shortdateformat year part set as a 2 digit year (ie “YY”) and a date with a year of 2000+ will return an incorrect 1900.. instead of 2000..  To correct, this change Delphi’s global variable ShortDateFormat to a 4 year digit.
e.g. ShortDateFormat := 'DD/MM/YYYY';
The problem has been corrected in Delphi 5.....

Thanking everyone in advance !!!!

Derrick Nel……..

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hi neld,

take a look to simonet's components

Hi Derrick,

I would suggest that you don't change the system's date format but do a simple call to:

DateTime_SetFormat(DateTimePicker1.Handle, 'ddMMyyy');

This format will be kept by the picker control even if the user changes the system's date format.

Ciao, Mike
If you only want to change the format for your Delphi application, simply add the following code in the form create of your first form.

ShortDateFormat := 'mm/dd/yyyy';

All subsequent Delphi dates in your application with use this format..

If you want to change it on your computer, use the Windows API call


The first parameter is the locale number to set, the second is which element to change (you probably want
LOCALE_SSHORTDATE) and the third is a wide string containing the new format.

If you need the LOCALE ID, use the
MAKELCID() macro with the constant LOCALE_SYSTEM_DEFAULT or

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

I think the previous comment solve your issue.

An other aproach is to change the registry directly.

The value is under HKEY_CURRENT_USER\Control Panel\International and the name of the parameter is sShortDate.

Anyway I haven't test if it works for the program after you change that value or it takes the value on initialization and doesn't work until you re-run the program
I don't believe that the applications short date format will solve the problem we are discussing here because the datetimepicker doesn't used this format and the VCL never changes the format the picker is using. Hence changing the short format has no effect on the picker.

Changing the systems locale information just to have a specific application looking a certain way is really ugly. What would you think when a cool program would change your entire desktop settings including the wallpaper just to meet its own layout? This is in no case good programming!

Ciao, Mike
neldAuthor Commented:
I Agree that it is in no case good programming to fiddle with a users personal settings, however the standard employed by our company to avoid Y2K issues is that all dates conform to the mm/dd/yyyy format.  All machines regional settings shortdate must comply to this standard.

What I have done is create a custom component inheriting from TDateTimePicker thereby providing all the existing functionality of the component.  I have overridden the components create constructor, inherited its create and add the Windows API SetLocaleInfo call which changes the shortdate format to dd/mm/yyyy, thereby ensuring that the machines regional settings comply with the standard as specified by my company.

I seem to have a much clearer understanding of the API now :-)

Thanks for your comment Mike, its much appreciated.......

neldAuthor Commented:
To JoeBooth,

Thanks for the API call, the following line of code works for everything as you suggest, with the exception of the DateTimePicker :-)
ShortDateFormat := 'dd/mm'yyyy';

In Delphi 3.0 at least, haven't tried it in Delphi 5.  JoeBooth answered my initial question so I'll allocate the points to you... TA

To Cecheto,

Changing the Registry directly is not an option as it totally screws up all the dates in your app.  I tried it before I posted the initial question :->
SetLocaleInfo() as suggested by JoeBooth works perfectly.

To Mike Lischke,

The following code intrigued me :
DateTime_SetFormat(DateTimePicker1.Handle, 'ddMMyyy');

Firstly my app wouldn't compile until I added COMMCTRL in my uses clause, then it did and it worked beautifully.  Mike if it is possible could you please gimme a little explaination of what it does ???

I'll also post another question so that you too can collect the points aswell as I think that this solution of yours is really the best.  The users personal settings are not affected and the code provides the required solution.

Thank You Mike !!!

To everyone who commented thanks a stax all of them were appreciated....

OkLoveYouByeBye...(Mindy animaniacs)

neldAuthor Commented:
Exactly what I asked for.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.