String Convert to Date Time Problem is Windows 98

  • Thread starter Thread starter Ryanfai
  • Start date Start date
R

Ryanfai

I use the vb.net make the program that save the date and any Information
field.
when I input the date in textbox then I save to database occurs error that
is
"Cast from string "20/08/2003" to type 'Date' is not valid.
I use this command change string to Date
dim year as date
dim strYear as string
=> year = ctype(stryear,Date).ADDYEAR(2)
I only in Windows 98 have problem
but In windows XP is not problem.
What wrong, and how can solve this problem and this commands have any error?
 
Hello,

Ryanfai said:
I use the vb.net make the program that save the date
and any Information field.
when I input the date in textbox then I save to database occurs
error that is
"Cast from string "20/08/2003" to type 'Date' is not valid.
I use this command change string to Date
dim year as date
dim strYear as string
=> year = ctype(stryear,Date).ADDYEAR(2)
I only in Windows 98 have problem
but In windows XP is not problem.
What wrong, and how can solve this problem and this
commands have any error?

I think that's caused by the format of the string (maybe it violates with
the locale settings of the computer). You may want to use 'DateTime.Parse'
instead.
 
Pass your date to this function and it will work fine.

Function ISODate(ByVal dteDate As Date) As String
If IsDate(dteDate) = True Then
Dim dteDay, dteMonth, dteYear
dteDay = dteDate.Day
dteMonth = dteDate.Month
dteYear = dteDate.Year
ISODate = dteYear & _
"-" & Right(CStr(dteMonth + 100), 2) & _
"-" & Right(CStr(dteDay + 100), 2)
Else
ISODate = Nothing
End If

End Function
 
Back
Top