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")?
Format RequirementsYou must enclose a Date literal within number signs ( # # ). You must specify the date value in the format M/d/yyyy, for example #5/31/1993# , or yyyy-MM-dd, for example #1993-5-31# . You can use slashes when specifying the year first.
DateTime dateTime16 = DateTime. ParseExact(dateString, new string[] { "MM. dd. yyyy", "MM-dd-yyyy", "MM/dd/yyyy" }, provider, DateTimeStyles.
It should be formatted like this: myDateTime. ToString("yyyy/MM/dd hh:mm:ss"); or myDateTime. ToString("yyyy/MM/dd); Because mm is for minute and for month MM should be used.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With