locked
Problem converting strings to DateTime value RRS feed

  • Question

  • User1160591469 posted

    I'm creating a webform which have 1 textbox(TextBox1) for Date that gets the date value from a calendar control, and 3 dropdownlists control for hour(timeHour), minute(timeMin) and am/pm(timeIn). I tried using DateTime.Parse method but it didnt work. Can anybody please help point out my mistake?


    Coding:

    Dim dDate As Date = TextBox1.Text

    Dim dt As Date = DateTime.Parse(timeInHour.SelectedValue.Trim() + ":" + timeInMin.SelectedValue.Trim() + ":00 " + timeIn.SelectedValue)

    Dim dTime As Date = dt

    Dim d As New Date(dDate.Year, dDate.Month, dDate.Day, dTime.Hour, dTime.Minute, dTime.Second, DateTimeKind.Local)

    ============================

    Error:

    [FormatException: String was not recognized as a valid DateTime.]

    ============================

    Wednesday, October 5, 2016 7:24 AM

Answers

  • User1160591469 posted

    Oops sorry. Don't bother this question. I just re-run the page and it suddenly works >.<

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 5, 2016 7:29 AM

All replies

  • User1160591469 posted

    Oops sorry. Don't bother this question. I just re-run the page and it suddenly works >.<

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 5, 2016 7:29 AM
  • User-1838255255 posted

    hi NurulShaf,

    Glad to hear your question has been resolved, please mark your reply to the answer!

    Best Regards,

    Eric Du

    Friday, October 7, 2016 1:36 AM