Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

convert date time to english ( us )

Posted on 2005-03-31
3
Medium Priority
?
263 Views
Last Modified: 2008-02-01
Hello,
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
0
Comment
Question by:mdiglio
  • 2
3 Comments
 
LVL 32

Expert Comment

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

e.g.

MsgBox Format(Now, "Short Date")

See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vafmtnameddateformats.asp
0
 
LVL 16

Author Comment

by:mdiglio
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 ?
0
 
LVL 32

Accepted Solution

by:
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
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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 Month15 days, 4 hours left to enroll

577 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