Search code examples
datetimevb6culture

Are date strings in VB6 relative to machine culture?


I have a legacy VB6 application which contains this code:

Begin VB.Label LblStDate 
            Alignment       =   1   'Right Justify
            AutoSize        =   -1  'True
            [Blah blah blah....]
            Top             =   0
            Width           =   75
End

[...]

LblStDate = Date

This makes the label LblStDate display the current date. On my machine, the label ends up displaying something like "27/08/2011" (that is, dd/mm/yyyy). Is it possible that the label would look different on a machine from another culture (for example, displaying "2011/08/27")?


Solution

  • Yes, VB6 does implicit type conversion, so in your case it is converting a Date type to a String using the user's locale and regional settings. Don't ever rely on a given format being used and once dates/times are converted to a string, you shouldn't really convert them back (unless under controlled circumstances).

    You can get the same result using the explicit CStr(Date) call.