Error in converting string to datetime

asp.net India
  • 18 years ago

    I am developing a web based application in asp.net. One of the screens takes as input the date field as string. In the code this string is converted to datetime using CType().


    The system setting on my machine are
    Local = English - United States
    Date format is mm/dd/yyyy


    I am getting the following error in while trying to CType():


    Error Message: Cast from string "12/20/2002" to type 'Date' is not


    valid.
    Stack Trace:
    System.InvalidCastException: Cast from string "12/20/2002" to type


    'Date' is not valid. at


    Microsoft.VisualBasic.CompilerServices.DateType.FromString(String


    Value, CultureInfo culture) at


    Microsoft.VisualBasic.CompilerServices.DateType.FromString(String


    Value) at EximPortal.TCS.Core.Utility.clsUtil.fnGetFormattedDate(String


    pstrDate) in


    C:\inetpub\wwwroot\EximPortal\Modules\Core\Utility\UtilManager.vb:line


    178 at EximPortal.TCS.Web.adNewsEventsMgmt1.cmdSave_Click(Object


    sender, EventArgs e) in


    C:\inetpub\wwwroot\EximPortal\SystemAdmin\NewsEvents\adNewsEventsMgmt.a


    spx.vb:line 131 at System.Web.UI.WebControls.Button.OnClick(EventArgs


    e) at


    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.Ra


    isePostBackEvent(String eventArgument) at


    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler


    sourceControl, String eventArgument) at


    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at


    System.Web.UI.Page.ProcessRequestMain()




    Can anybody help in resolving this error.



Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“My definition of an expert in any field is a person who knows enough about what's really going on to be scared.” - P. J. Plauger