locked
VS2005:Problem with datetime format while conactenating values in textboxes RRS feed

  • Question

  • User-1296705841 posted

    Hi,
       I have 3 textbox as txtdate,txtintime & txtouttime.Here i'm using ajaxcalendar and ajax maskededitcontrol for the
    textboxes.txtintime & outtime will be in "HH:MM" format.I have to check whether outime>intime using datediff function.
    So for that i'm trying to concatenate the values in txtdate&txtintime which will have to be in format as "10/12/2009 10:00PM".
    I tried with convert.datetime & datetime.parse.
    But it failed to work out.
    Can anyone tell how to do it?


    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    Sunday, December 13, 2009 12:18 PM

Answers

  • User-952121411 posted

    Assuming this is not a Globilization issue, and you are using a U.S. format of MM/DD/YYYY and that is the date format you are accepting, the code you have posted (that includes a space between the date and time values) should work.  I tested it myself using the values you provided and it works.

    The next step is to debug the code and post back to this thread with the following values (from debugger, not from just what you are entering on the .aspx page):

    1. txtDate.Text
    2. txtIntime.Text
    3. userin

    Seeing those exact values from debugging before the conversion should show the issue.  If you are using a different 'globalization culture' setting or something not as the U.S., you will need to form that string into the proper format before doing the conversion in order for it to work properly.


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 16, 2009 8:59 AM

All replies

  • User-1247685454 posted

    What is the problem?

    This code is working fine

            Dim a As String = txtDate.Text
            Dim b As String = txtTime.Text
            Dim c As String = a + " " + b
            Dim d As DateTime = Convert.ToDateTime(c)
            Response.Write(d)


    Monday, December 14, 2009 1:11 AM
  • User-1296705841 posted

    Hi hitesh,

    thanks for ur reply.

       Below is my code.

    Dim userin As String = txtDate.Text + " " + txtIntime.Text

    Dim intime As DateTime = Convert.ToDateTime(userin) //error showed here

    while running my code, it has shown error as "String was not recognized as a valid DateTime."




    <input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

    Monday, December 14, 2009 3:04 AM
  • User-1247685454 posted

    give space between double quotes ->"Blank Space Here"


    Monday, December 14, 2009 3:49 AM
  • User-952121411 posted

    Assuming this is not a Globilization issue, and you are using a U.S. format of MM/DD/YYYY and that is the date format you are accepting, the code you have posted (that includes a space between the date and time values) should work.  I tested it myself using the values you provided and it works.

    The next step is to debug the code and post back to this thread with the following values (from debugger, not from just what you are entering on the .aspx page):

    1. txtDate.Text
    2. txtIntime.Text
    3. userin

    Seeing those exact values from debugging before the conversion should show the issue.  If you are using a different 'globalization culture' setting or something not as the U.S., you will need to form that string into the proper format before doing the conversion in order for it to work properly.


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 16, 2009 8:59 AM