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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 07-06-2006 1:11pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 684 ✭✭✭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