Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting DateFormat more accurate

Posted on 2007-12-03
6
Medium Priority
?
2,037 Views
Last Modified: 2010-04-21
Hi,

In my Delphi application I set the dateformat like below in the OnCreate-event of the main form.
  DateSeparator := '-';
  ShortDateFormat := 'd/M/yyyy';

But when a user is starting MS Access (UK) this dataformat is apparently changed.
So when a user is starting-up my application and then starts-up MS Access, the dateformat needed in my app is lost.
Is there any way to make sure my application will hold on to this dateformat (preferably without disturbing MS Access or any other app)?
0
Comment
Question by:Delphiwizard
[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
6 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20397263
changing the dateformat is something you'd rather not do.
If often means a design flaw somewhere else in the code.

Can you explain why you need to change it?
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 20397715
I prefer to avoid changing the Date and Time formats and try to use the FormatDateTime function to display or manipulate date strings.
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 20400127
you can set the display format on the actual field if you prefer.
myField.DisplayFormat := 'd/MM/yyyy';
(you can do this in the object inspector also)
0
Independent Software Vendors: 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!

 
LVL 13

Expert Comment

by:rfwoolf
ID: 20400194
If MSAccess is your database server, its common for database server to have its own dateformat usually set to the system's default when installed.
For this reason and other's It is not best-practise to change the date format on the system itself.
I know this creates more work and can be very frustrating.

You can go through your application and make sure you don't use hard-coded string-to-date conversions like strtodatetime('19/01/2007') because on a system with the date format of mm/dd/yyyy it will cause an error.
You can look for other alternatives, like EncodeDate (you will need to add DateUtils to your unit's Uses clause). EncodeDate allows you to set a TDateTime variable regardless of the system's date format.
0
 
LVL 25

Accepted Solution

by:
imitchie earned 2000 total points
ID: 20401424
Make sure the changes are from SysUtils, i.e.
  SysUtils.DateSeparator := '-';
  SysUtils.ShortDateFormat := 'd/M/yyyy';
then add this line
  application.UpdateFormatSettings := False;

FYI - these changes affect your Delphi program only and in no way affects System Regional settings! Relax

From Delphi Help
================
The Sysutils unit includes a number of variables that are used by various formatting routines. Values are assigned to these variables to define the formats of numeric and date/time strings. The initial values of these variables are fetched from the system registry using the GetLocaleInfo function in the Win32 API. VCL (non-console) applications automatically update these formatting variables in response to WM_WININICHANGE messages. The Application variables UpdateFormatSettings method either allows or disallows changes in system settings. The default is True. Set this property to False to prevent the system settings from changing.
0
 

Author Closing Comment

by:Delphiwizard
ID: 31412381
Thank you very much.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

705 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