Force date to US format regardless of locale settings

cultureinfodateformattinglocalizationvb6

I have a VB6 program with this line:

strDate = Format(Date, "ddmmmyyyy")

I need it to always come out in this format according to the Cultural settings for Windows for English (United States):

17Jul2012

Unfortunately when the culture is set to something else, French, for example, I get this:

17juil2012

Is there any way to make the date format always use the English US formatting?

Best Answer

Rather than mess about trying to enforce a culture-specific format, why not just hard code the month names into a simple function like this:

Private Function GetEnglishDate(ByVal d As Date) As String
    Dim monthNames
    monthNames = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    GetEnglishDate = Day(d) & monthNames(Month(d)) & Year(d)
End Function

Usage:

strDate = GetEnglishDate(myDate)