I make a program on Windows7 with VB.NET 2008 which uses dates and datetime pickers which work’s good.
Like this:
With dtp_date1
'here crashes
.Text = DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 00:00:00"
.Format = DateTimePickerFormat.Custom
.CustomFormat = "dd.MM.yyyy. HH:mm:ss tt"
.ShowUpDown = False
End With
With dtp_date2
.Text = DateTime.Now.Date.ToString("dd.MM.yyyy.") & " 23:59:59.9999"
.Format = DateTimePickerFormat.Custom
.CustomFormat = "dd.MM.yyyy. HH:mm:ss tt"
.ShowUpDown = False
End With
This works OK untill I put this program to windows XP.
Error appears:
string was not recognized as a valid Datetime
I try to fix this so:
.Text = CDate(DateTimeNow.Date.ToString("dd.MM.yyyy.") & " 00:00:00").ToString
And here get error:
Conversion from string “06.01.2013. 00.00.00” to type ‘Date’ is not valid.
Since I have many places in program with dates what to do to fix this error?
Never assign the DateTimePicker.Text property. You’ll get slammed if the format of your string doesn’t match the culture or the Control Panel overrides for the date/time format.
Always use the DateTimePicker.Value property. A property of type DateTime, immune to format problems. Fix: