I want to convert date which is stored as string in a SQL Server 2008 database to smalldatetime.
The format for the saved string is 16/12/2007 and I want to remove / and replace it with - to get proper date format which is 16-12-2007
I getting the following error
Conversion from string "16/12/2007" to type 'Date' is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Conversion from string "16/12/2007" to type 'Date' is not valid.
Source Error:
Line 34: NewsItem.Visible = True
Line 35: NewsItem.Date_Modified = CDate(GetContent.Ndate)
Line 36: NewsItem.Date_Published = CDate(GetContent.Ndate)
I thought of creating a function that replace the / character with - to then update the database but it will take long time.
dateanddatetime2data types, which ADO.NET knows how to translate to and from .NETDateTimetypes. You only encounter formatting issues if you deviate from this and use inappropriate storage types.