convert varchar field in sql database into datetime value while retrieving to display

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muthukumar bala
    New Member
    • Feb 2013
    • 1

    convert varchar field in sql database into datetime value while retrieving to display

    Code:
    DateTimePicker1.Text = reader(Convert.ToDateTime("PURCHASED_DATE"))
    this is my code the PURCHASED_DATE field is varchar(50) datatype but when retriving it should be in datetime format

    the error is "the string was not recognised as a valid datetime.there is a unknown word starting at index 0
    please help me to over come the problem
    Last edited by zmbd; Feb 23 '13, 10:27 PM. Reason: [Z{Please use the <CODE/> formatting button to format your posted code and SQL}]
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You would need to post the values that it says is not a valid date time value.

    Comment

    • Mikkeee
      New Member
      • Feb 2013
      • 94

      #3
      Your code is converting the string "PURCHASED_DATE " instead of the reader value. Try this:
      Code:
        Convert.ToDateTime(reader("PURCHASED_DATE"))

      Comment

      Working...