convert date time to english ( us )

Posted on 2005-03-31
Medium Priority
Last Modified: 2008-02-01
I have a login script that is grabbing some user information along with the date and writing the info to a text file

Previosuly I asked a question about how to convert a date from different formats like
3.29.05 or 3/29/2005 to this format 03/29/2005  ( http:Q_21368889.html )

Now I realize that some users have changed their date/time settings to output a time having the month first e.g. 31.3.2005

How can I get their date to be like the others from my script?
I do not want to change their settings

is there anything like...

if date-time/format does not equal english ( US) then
convert the given date-time to english us

I'm using vbscript right now but can put this in a vb app if I need to.
I will be getting the current date/time and placing it into a text file.

Thank you for your time.
If this was not enough info let me know and I will post whatever is needed
Question by:mdiglio
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
  • 2
LVL 32

Expert Comment

ID: 13677533
Using the Format function along with named date formats will output the date in the system's default format:


MsgBox Format(Now, "Short Date")

LVL 16

Author Comment

ID: 13677583
Hi Erick,
Thank you for your response.

The problem I have is that I dont want to use the system's default format.
Some users have it setup differently and in different regional settings like English ( Australia )
which gives me a date that has the month first

I am outputting the date and time to a text file and would like them to all be the same in this text file

Is there any way I can query the system and return the regional options ?
LVL 32

Accepted Solution

Erick37 earned 2000 total points
ID: 13677634
You can get the current user's settings like this:

' Modified from a sample found here:
' http://vbnet.mvps.org/code/locale/localeenumdates.htm

Option Explicit

Private Const DATE_LONGDATE As Long = &H2
Private Const DATE_SHORTDATE As Long = &H1
Private Const LOCALE_SLANGUAGE As Long = &H2 'localized name of language
Private Const LOCALE_SSHORTDATE As Long = &H1F 'short date format string
Private Const LOCALE_SLONGDATE As Long = &H20 'long date format string

Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long

Private Declare Function GetLocaleInfo Lib "kernel32" _
   Alias "GetLocaleInfoA" _
  (ByVal Locale As Long, _
   ByVal LCType As Long, _
   ByVal lpLCData As String, _
   ByVal cchData As Long) As Long

Private Function GetUserLocaleInfo(ByVal dwLocaleID As Long, ByVal dwLCType As Long) As String

    Dim sReturn As String
    Dim r As Long
    sReturn = Space$(1024)
    'call the function passing the Locale type
    r = GetLocaleInfo(dwLocaleID, dwLCType, sReturn, Len(sReturn))
    'if successful..
    If r Then
        'r contains number of characters copied + null terminator
        GetUserLocaleInfo = Left$(sReturn, r - 1)
    End If
End Function

Private Sub Command1_Click()
    Dim LCID As Long
    'get the Location ID
    LCID = GetUserDefaultLCID()
    'get the short date format
    MsgBox GetUserLocaleInfo(LCID, LOCALE_SSHORTDATE)

End Sub

Featured Post

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.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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