Regional Settings change vba date formatting

greegan

Well-known Member
Joined
Nov 18, 2009
Messages
643
Office Version
  1. 365
Platform
  1. Windows
I'm hoping this is something simple to do.

We are in Canada, so the date format standard is different from the US, its dd/mm/yyyy or dd/mm/yy (the day is first rather than month at least). My supervisor's station is set to Canadian formatting for the regional settings, and he won't change this.
The rest of the team is set for US settings. To clarifiy, we understand this to be mm/dd/yyyy or mm/dd/yy.

I have an application which has code which accepts the date format as m/d/yyyy format. This works no matter the regional settings, with a bit of a hitch...
When my supervisor enters the date, the date is switched around for his regional settings when the file saves with date as part of the filename.

I will add the opening code as well as the file save code here if needed. I'm hoping there is something I can use to check on regional settings and adjust the file save date formatting based on these settings.

-- g
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
regional setting of windows can be checked with:
Application.International(xlCountrySetting)

see also International Property [Excel 2007 Developer Reference]
http://msdn.microsoft.com/en-us/library/bb177675(v=office.12).aspx

especially:
Application.International(xlMDY)
True if the date order is month-day-year for dates displayed in the long form; False if the date order is day-month-year.
 
Last edited:
Upvote 0
I use sometimes

Code:
Sub reg_set()
Dim dtTest As Date
 
dtTest = CDate("01/10/12")
 
Select Case Day(dtTest)
Case 1
    MsgBox "dd/mm/yy"
Case 2
    MsgBox "mm/dd/yy"
End Select
End Sub

to read regional setting or the following should work as well

Code:
Sub RegionalDateFormat()
    Dim DateOrder As String
    Dim DateSeparator As String
   
With Application
    Select Case .International(xlDateOrder)
        Case Is = 0
            DateOrder = "month-day-year"
        Case Is = 1
            DateOrder = "day-month-year"
        Case Is = 2
            DateOrder = "year-month-day"
        Case Else
            DateOrder = "Error"
    End Select
   
    DateSeparator = .International(xlDateSeparator)
End With

Debug.Print "Date Order: ", DateOrder
Debug.Print "Date Separator: ", DateSeparator
End Sub
 
Upvote 0
Hi

Not a solution, just a remark: can't you have the date input in international format: yyyy-mm-dd?

If you use the international date format as input, instead of some regional format, it should read the date without problem and should adjust automatically to whatever default regional date format a specific PC has.

This way you'd not worry if the program runs in US or Canada or Germany or wherever.
 
Upvote 0
Hi

Not a solution, just a remark: can't you have the date input in international format: yyyy-mm-dd?

If you use the international date format as input, instead of some regional format, it should read the date without problem and should adjust automatically to whatever default regional date format a specific PC has.

This way you'd not worry if the program runs in US or Canada or Germany or wherever.

I would never had thought of this. Thank you
And thank you to all of you for the other responses. I will check out the link and the code this week. I will be happy to let you know how it turns out.

-- g
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,692
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top