Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

convert string to date (c#) - help !!!

Options
  • 07-06-2006 2:11pm
    #1
    Registered Users Posts: 872 ✭✭✭


    Hi,

    I thought this would be simple to do but it is causing me much grief.

    Basically i have a date coming out of an array as 09:10 14/03/2006

    i want to add this value into a datetime(8) column.

    I pass the value form the array to the sp as a string but i am getting

    "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value"

    Please help

    Thanks


Comments

  • Registered Users Posts: 1,466 ✭✭✭Smoggy


    Here are two suggestions :

    before you take it out of the array , pass it into a variable of type date and then into your sp param

    or

    In your tsql code accept the data as a varchar and then use convert / cast to change it into the required datetime format.


  • Registered Users Posts: 683 ✭✭✭Gosh


    Use the DateTime.Parse method


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    The usual form of a DateTime is to have the Date first... so you may have to manually parse the string. I.e. split it up into seperate variables for hours/mins/day/month/year then go:

    DateTime theDate = new DateTime(year, month, days, hours, minutes);

    Then pass that datetime to your SQL as a datetime object.


Advertisement