Converstion of date Format
I have wrtten a Vb script that will convert the date in the Format " 07 Mar 2013" to 07/03/2013 i.e is stored in the registry.
I have used Cdate(07 Mar 2013) function.
But when the region is diffrent the Cdate will throw error " Type Mismatch". For e.g in german it is "07 Marz 2013" Cdate(07 Marz 2013). Could anybody help me for date convertion for any region?
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
anonymous_9363
11 years ago
Here's some code I have had lying around since I don't know when which will divine the locale of the machine. You can then do a translation of dates once you know that.
Option Explicit
Dim objLocaleDictionary
Dim intLocale
Dim strLocale
Dim blnResult
Dim strFullDetails
Dim strShortName
Dim strHexCode
Dim strLongName
Dim strMsg
intLocale = GetLocale
strLocale = CStr(intLocale)
'// You never know...
If Len(strLocale) = 0 Then
'// Display error message
End If
blnResult = GetLocaleDetails(strLocale, strFullDetails)
If Not blnResult Then
'// Display error message
WScript.Quit(2)
End If
If IsEmpty(strFullDetails) Then
'// Display error message
WScript.Quit(2)
End If
If Len(strFullDetails) = 0 Then
'// Display error message
WScript.Quit(2)
End If
strShortName = Split(strFullDetails, ",")(0)
strHexCode = Split(strFullDetails, ",")(1)
strLongName = Split(strFullDetails, ",")(2)
strMsg = ""
strMsg = strMsg & "For locale ID " & strLocale & "," & vbCRLF
strMsg = strMsg & "The short name is " & vbTAB & strShortName & vbCRLF
strMsg = strMsg & "The hex code is " & vbTAB & strHexCode & vbCRLF
strMsg = strMsg & "The long name is " & vbTAB & strLongName
MsgBox strMsg
Function GetLocaleDetails(ByVal strLocaleIn, ByRef strDetails)
Dim objItem
Dim objDictArray
Dim strItem
Dim intIndex
Call BuildDictionary
GetLocaleDetails = False
On Error Resume Next
With objLocaleDictionary
'// LOL...can't do this! It's expecting something in quotes. Needless to say, no error is thrown...
'// If .Exists(strLocaleIn) Then
'// GetLocaleDetails = True
'// strFullDetails = .Item(strLocale)
'// End If
'// So we have to resort through looping through the whole dictionary!
objDictArray = .Keys
For intIndex = 0 To .Count - 1
If Trim(objDictArray(intIndex)) = strLocaleIn Then
GetLocaleDetails = True
strFullDetails = .Item(objDictArray(intIndex))
Exit For
End If
Next
End With
Set objLocaleDictionary = Nothing
End Function
Sub BuildDictionary
Set objLocaleDictionary = CreateObject("Scripting.Dictionary")
With objLocaleDictionary
.Add "1078", "af,0x0436,Afrikaans"
.Add "1052", "sq,0x041C,Albanian"
.Add "14337", "ar-ae,0x3801,Arabic - United Arab Emirates"
.Add "15361", "ar-bh,0x3C01,Arabic - Bahrain"
.Add "5121", "ar-dz,0x1401,Arabic - Algeria"
.Add "3073", "ar-eg,0x0C01,Arabic - Egypt"
.Add "2049", "ar-iq,0x0801,Arabic - Iraq"
.Add "11265", "ar-jo,0x2C01,Arabic - Jordan"
.Add "13313", "ar-kw,0x3401,Arabic - Kuwait"
.Add "12289", "ar-lb,0x3001,Arabic - Lebanon"
.Add "4097", "ar-ly,0x1001,Arabic - Libya"
.Add "6145", "ar-ma,0x1801,Arabic - Morocco"
.Add "8193", "ar-om,0x2001,Arabic - Oman"
.Add "16385", "ar-qa,0x4001,Arabic - Qatar"
.Add "1025", "ar-sa,0x0401,Arabic - Saudi Arabia"
.Add "10241", "ar-sy,0x2801,Arabic - Syria"
.Add "7169", "ar-tn,0x1C01,Arabic - Tunisia"
.Add "9217", "ar-ye,0x2401,Arabic - Yemen"
.Add "1067", "hy,0x042B,Armenian"
.Add "1068", "az-az,0x042C,Azeri - Latin"
.Add "2092", "az-az,0x082C,Azeri - Cyrillic"
.Add "1069", "eu,0x042D,Basque"
.Add "1059", "be,0x0423,Belarusian"
.Add "1026", "bg,0x0402,Bulgarian"
.Add "1027", "ca,0x0403,Catalan"
.Add "2052", "zh-cn,0x0804,Chinese - China"
.Add "3076", "zh-hk,0x0C04,Chinese - Hong Kong S.A.R."
.Add "5124", "zh-mo,0x1404,Chinese - Macau S.A.R"
.Add "4100", "zh-sg,0x1004,Chinese - Singapore"
.Add "1028", "zh-tw,0x0404,Chinese - Taiwan"
.Add "1050", "hr,0x041A,Croatian"
.Add "1029", "cs,0x0405,Czech"
.Add "1030", "da,0x0406,Danish"
.Add "1043", "nl-nl,0x0413,Dutch - The Netherlands"
.Add "2067", "nl-be,0x0813,Dutch - Belgium"
.Add "3081", "en-au,0x0C09,English - Australia"
.Add "10249", "en-bz,0x2809,English - Belize"
.Add "4105", "en-ca,0x1009,English - Canada"
.Add "9225", "en-cb,0x2409,English - Carribbean"
.Add "6153", "en-ie,0x1809,English - Ireland"
.Add "8201", "en-jm,0x2009,English - Jamaica"
.Add "5129", "en-nz,0x1409,English - New Zealand"
.Add "13321", "en-ph,0x3409,English - Phillippines"
.Add "7177", "en-za,0x1C09,English - South Africa"
.Add "11273", "en-tt,0x2C09,English - Trinidad"
.Add "2057", "en-gb,0x0809,English - United Kingdom"
.Add "1033", "en-us,0x0409,English - United States"
.Add "1061", "et,0x0425,Estonian"
.Add "1065", "fa,0x0429,Farsi"
.Add "1035", "fi,0x040B,Finnish"
.Add "1080", "fo,0x0438,Faroese"
.Add "1036", "fr-fr,0x040C,French - France"
.Add "2060", "fr-be,0x080C,French - Belgium"
.Add "3084", "fr-ca,0x0C0C,French - Canada"
.Add "5132", "fr-lu,0x140C,French - Luxembourg"
.Add "4108", "fr-ch,0x100C,French - Switzerland"
.Add "2108", "gd-ie,0x083C,Gaelic - Ireland"
.Add "1084", "gd,0x043C,Gaelic - Scotland"
.Add "1031", "de-de,0x0407,German - Germany"
.Add "3079", "de-at,0x0C07,German - Austria"
.Add "5127", "de-li,0x1407,German - Liechtenstein"
.Add "4103", "de-lu,0x1007,German - Luxembourg"
.Add "2055", "de-ch,0x0807,German - Switzerland"
.Add "1032", "el,0x0408,Greek"
.Add "1037", "he,0x040D,Hebrew"
.Add "1081", "hi,0x0439,Hindi"
.Add "1038", "hu,0x040E,Hungarian"
.Add "1039", "is,0x040F,Icelandic"
.Add "1057", "id,0x0421,Indonesian"
.Add "1040", "it-it,0x0410,Italian - Italy"
.Add "2064", "it-ch,0x0810,Italian - Switzerland"
.Add "1041", "ja,0x0411,Japanese"
.Add "1042", "ko,0x0412,Korean"
.Add "1062", "lv,0x0426,Latvian"
.Add "1063", "lt,0x0427,Lithuanian"
.Add "1071", "mk,0x042F,FYRO Macedonian"
.Add "1086", "ms-my,0x043E,Malay - Malaysia"
.Add "2110", "ms-bn,0x083E,Malay - Brunei"
.Add "1082", "mt,0x043A,Maltese"
.Add "1102", "mr,0x044E,Marathi"
.Add "1044", "no-no,0x0414,Norwegian - Bokmål"
.Add "2068", "no-no,0x0814,Norwegian - Nynorsk"
.Add "1045", "pl,0x0415,Polish"
.Add "2070", "pt-pt,0x0816,Portuguese - Portugal"
.Add "1046", "pt-br,0x0416,Portuguese - Brazil"
.Add "1047", "rm,0x0417,Raeto-Romance"
.Add "1048", "ro,0x0418,Romanian - Romania"
.Add "2072", "ro-mo,0x0818,Romanian - Moldova"
.Add "1049", "ru,0x0419,Russian"
.Add "2073", "ru-mo,0x0819,Russian - Moldova"
.Add "1103", "sa,0x044F,Sanskrit"
.Add "3098", "sr-sp,0x0C1A,Serbian - Cyrillic"
.Add "2074", "sr-sp,0x081A,Serbian - Latin"
.Add "1074", "tn,0x0432,Setsuana"
.Add "1060", "sl,0x0424,Slovenian"
.Add "1051", "sk,0x041B,Slovak"
.Add "1070", "sb,0x042E,Sorbian"
.Add "1034", "es-es,0x0C0A,Spanish - Spain"
.Add "11274", "es-ar,0x2C0A,Spanish - Argentina"
.Add "16394", "es-bo,0x400A,Spanish - Bolivia"
.Add "13322", "es-cl,0x340A,Spanish - Chile"
.Add "9226", "es-co,0x240A,Spanish - Colombia"
.Add "5130", "es-cr,0x140A,Spanish - Costa Rica"
.Add "7178", "es-do,0x1C0A,Spanish - Dominican Republic"
.Add "12298", "es-ec,0x300A,Spanish - Ecuador"
.Add "4106", "es-gt,0x100A,Spanish - Guatemala"
.Add "18442", "es-hn,0x480A,Spanish - Honduras"
.Add "2058", "es-mx,0x080A,Spanish - Mexico"
.Add "19466", "es-ni,0x4C0A,Spanish - Nicaragua"
.Add "6154", "es-pa,0x180A,Spanish - Panama"
.Add "10250", "es-pe,0x280A,Spanish - Peru"
.Add "20490", "es-pr,0x500A,Spanish - Puerto Rico"
.Add "15370", "es-py,0x3C0A,Spanish - Paraguay"
.Add "17418", "es-sv,0x440A,Spanish - El Salvador"
.Add "14346", "es-uy,0x380A,Spanish - Uruguay"
.Add "8202", "es-ve,0x200A,Spanish - Venezuela"
.Add "1072", "sx,0x0430,Sutu"
.Add "1089", "sw,0x0441,Swahili"
.Add "1053", "sv-se,0x041D,Swedish - Sweden"
.Add "2077", "sv-fi,0x081D,Swedish - Finland"
.Add "1097", "ta,0x0449,Tamil"
.Add "1092", "tt,0X0444,Tatar"
.Add "1054", "th,0x041E,Thai"
.Add "1055", "tr,0x041F,Turkish"
.Add "1073", "ts,0x0431,Tsonga"
.Add "1058", "uk,0x0422,Ukrainian"
.Add "1056", "ur,0x0420,Urdu"
.Add "2115", "uz-uz,0x0843,Uzbek - Cyrillic"
.Add "1091", "uz-uz,0x0443,Uzbek - Latin"
.Add "1066", "vi,0x042A,Vietnamese"
.Add "1076", "xh,0x0434,Xhosa"
.Add "1085", "yi,0x043D,Yiddish"
.Add "1077", "zu,0x0435,Zulu"
End With
End Sub
Posted by:
virtualize
11 years ago