Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2041
  • Last Modified:

Setting DateFormat more accurate

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
Stef Merlijn
Asked:
Stef Merlijn
1 Solution
 
MerijnBSr. Software EngineerCommented:
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
 
SteveBayCommented:
I prefer to avoid changing the Date and Time formats and try to use the FormatDateTime function to display or manipulate date strings.
0
 
TheRealLokiSenior DeveloperCommented:
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
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.

 
rfwoolfCommented:
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
 
imitchieCommented:
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
 
Stef MerlijnDeveloperAuthor Commented:
Thank you very much.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now