|
Question : Date Format in Windows App
|
|
I have a Windows App with some DateTimePicker controls in my App I use date format like 'dd/MM/yyyy', when distrubute my app to other PC with another Regional Configuration (DateFormat 'MM/dd/yyyy') I get some errors like "Cast from string "31/3/2008" to type 'Date' is not valid".
I want to keep DateFormat 'dd/MM/yyyy' not matter PC regional configuration. I'm using VB.net 2003.
Any suggest?
Thanks in advance.
|
|
Answer : Date Format in Windows App
|
|
If you can code the first day of the month by coding
_DateStr1= "1" + "/" + "3" + "/" + "2008" _Date1 = CDate(_DateStr1)
I don't understand why can't you do it by coding
_Date1 = New DateTime(2008, 3, 1)
instead. And if you can code the last day of the month by coding
_DateStr1= "31" + "/" + "3" + "/" + "2008" _Date1 = CDate(_DateStr1)
I don't understand why can't you do it by coding
_Date1 = New DateTime(2008, 3, 31)
instead. The difference between the two methods is that the first is culture-dependent, "so when format date is different from dd/MM/yyyy I get error". The second is culture-independent: it will work whatever the settings on the local machine.
But it's your app.
Roger
|
|
|
|