Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EnumDateFormats to change the time regional setting

Status
Not open for further replies.

applek

Programmer
Nov 18, 2002
15
US
Hi, all.

Is there anyway to change the time regional setting at application run-time according to my format? I have found some source code, there is some limitation as i would like to change the time format to dd/mm/yyyy and inside the setting, it doesn't have this kind of setting. Could we change the format to our defined-setting? As i understand that The EnumDateFormats is to get the ID from the callback EnumDateFormatsProc as it get the date string from the system. Can we programmatically code it to add the string and let the EnumDateFormatsProc to generate the ID? Pls advise.
 

>Is there anyway to change the time regional setting at application run-time according to my format?

You do not want to do this!

Better, would be to use the Format function to display your data the way that you want.
Other than that, there should be never a need to do this, unless the user is fully aware that you ARE doing this, and can interact with it.

Checking the time settings is a different issue, especially if an application is designed for a specific region. If you need help doing this, then let me know.

If you want to change the settings, best is to check the settings, and if undesirable, then inform the user to make the changes in the control panel, or call up the control panel for the user:

Call Shell("rundll32.exe shell32.dll,Control_RunDLL intl.cpl,,3", vbNormalFocus) [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks CCLINT.

Well, i do this has my own purpose. I do encounter a problem where my application is written in VB and the DB is SQL server. My pc setting is "dd/mm/yyyy" and the application can run in my PC. However, it couldn't run in other PC as i discovered that there is other type of date setting. We have to manually change the user PC before running the application. In order to avoid any manually changes on the PC setting, i wonder whether it can change it programmatically when running the application. Pls advise.
 

Then it sounds like you didn't consider the different locals from the beginning (mistake made by many).

If done right, you should never have to change the settings for time and date...no matter what format they are in. The date conversion/calculation functions will format/calculate correctly based on these settings.
So you can let the user summit a date based on these settings, stick them in date variables, or pass them to date functions, and they will calculate correctly and return a value in the same format.

However, concerning passing a date to a provider (or any other function that requires a strict format), the date needs to be converted to that format, prior to passing it to it:
If you know the format required by the provider, then you can change a date, (which is formated to the settings in the control panel), to the format required by the provider. This is the correct method of approach.

Example:
Pass a date to the JET provider (Requires Date in US format and # as date identifier: #USDate#:

Public Const gcSQLDATETIME = "mm\/dd\/yyyy hh\:nn\:ss"
Public Const gcSQLDATE = "mm\/dd\/yyyy"
Public Const gcSQLDATEID = "#"

Dim dtSomeDate As Date
dtSomeDate =Date

Debug.Print dtSomeDate 'returns a date in the format as set in the Date tab of the international settings of the control panel - in this case: dd.mm.yy

'Format the date to be passed to the JET provider, which is required to be: mm/dd/yyyy
"...WHERE DateField = " & gcSQLDATEID & Format$(dtSomeDate,gcSQLDATE) & gcSQLDATEID
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thank you very much. I did solve my problem :)
 

>I did solve my problem

And, what method did you use to solve the problem? [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
I'm using the SetLocaleInfo function to overwrite the region setting of the time.

Thanks anyway:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top