Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 07-06-2006 02: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,454 ✭✭✭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