Re: Retrieving short system date format in VBA



Thanks Rick, this is excaclty what I'm looking for.
--
Rocco Coetzee


"Rick Rothstein" wrote:

You are looking for the pattern of the short date format, not a date in that
format, correct? Here is one way to get it...

Function DateFormat() As String
DateFormat = FormatDateTime(DateSerial(2003, 1, 2), vbShortDate)
DateFormat = Replace(DateFormat, "2003", "YYYY")
DateFormat = Replace(DateFormat, "03", "YY")
DateFormat = Replace(DateFormat, "01", "MM")
DateFormat = Replace(DateFormat, "1", "M")
DateFormat = Replace(DateFormat, "02", "dd")
DateFormat = Replace(DateFormat, "2", "d")
DateFormat = Replace(DateFormat, MonthName(1), "MMMM")
DateFormat = Replace(DateFormat, MonthName(1, True), "MMM")
End Function

If it helps any, you can get the time format pattern using this function...

Function TimeFormat() As String
TimeFormat = CStr(TimeSerial(13, 22, 44))
TimeFormat = Replace(TimeFormat, "22", "mm")
TimeFormat = Replace(TimeFormat, "44", "ss")
If InStr(TimeFormat, "13") > 0 Then
TimeFormat = Replace(TimeFormat, "13", "HH")
If InStr(CStr(TimeSerial(1, 22, 44)), "0") = 0 Then
TimeFormat = Replace(TimeFormat, "HH", "H")
End If
Else
TimeFormat = Replace(TimeFormat, "1", "h")
TimeFormat = Replace(TimeFormat, "0", "h")
TimeFormat = Replace(TimeFormat, "PM", "tt", , , vbTextCompare)
End If
End Function

--
Rick (MVP - Excel)


"RoccoCoetzee" <RoccoCoetzee@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:27620E0C-E8E1-4233-92B4-F893414CEAC6@xxxxxxxxxxxxxxxx
Hi

Can someone please help me retrieving the system short date format (I
presume it’s from local)

I have managed to do that from Visual Studio (VB) with the following line.

SystemShortDateFormat =
System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern

How do I accomplish this in VBA?

--
Rocco Coetzee


.


Loading