Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem in Date Format

Problem in Date Format

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CrazyCoder26
    wrote on last edited by
    #1

    Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards

    ARINDAM

    A N S K 4 Replies Last reply
    0
    • C CrazyCoder26

      Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards

      ARINDAM

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      ARINDAM1981 wrote:

      Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime".

      What input are you giving for the text?

      cheers, Abhijit CodeProject MVP

      C 1 Reply Last reply
      0
      • A Abhijit Jana

        ARINDAM1981 wrote:

        Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime".

        What input are you giving for the text?

        cheers, Abhijit CodeProject MVP

        C Offline
        C Offline
        CrazyCoder26
        wrote on last edited by
        #3

        the input in my text is exactly as the following 16/04/2009

        ARINDAM

        A 1 Reply Last reply
        0
        • C CrazyCoder26

          the input in my text is exactly as the following 16/04/2009

          ARINDAM

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          ARINDAM1981 wrote:

          the input in my text is exactly as the following 16/04/2009

          if the input is same for both case check the date time settings on server, weather it is dd/mm/yyyy or mm/dd/yyyy. I will suggest you to use DateTime.Parse() and use Current Culterinfo for the convertion.

          cheers, Abhijit CodeProject MVP

          1 Reply Last reply
          0
          • C CrazyCoder26

            Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards

            ARINDAM

            N Offline
            N Offline
            nithydurai
            wrote on last edited by
            #5

            create the date column in Datetime type.... eg create table tablename(date datetime)

            A 1 Reply Last reply
            0
            • N nithydurai

              create the date column in Datetime type.... eg create table tablename(date datetime)

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              nithydurai wrote:

              create the date column in Datetime type.... eg create table tablename(date datetime)

              What is the relation between the Question and your answer?:confused:

              cheers, Abhijit CodeProject MVP

              N 1 Reply Last reply
              0
              • A Abhijit Jana

                nithydurai wrote:

                create the date column in Datetime type.... eg create table tablename(date datetime)

                What is the relation between the Question and your answer?:confused:

                cheers, Abhijit CodeProject MVP

                N Offline
                N Offline
                nithydurai
                wrote on last edited by
                #7

                i think u are create the date column in string format....

                1 Reply Last reply
                0
                • C CrazyCoder26

                  Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards

                  ARINDAM

                  S Offline
                  S Offline
                  SayreCC
                  wrote on last edited by
                  #8

                  Hi, try this textbox1.text = string.format("{0:G}",datetime.now); or visit this http://codeincsharp.blogspot.com/2008/05/different-date-format-in-c.html Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.

                  modified on Tuesday, April 28, 2009 3:07 AM

                  A 1 Reply Last reply
                  0
                  • S SayreCC

                    Hi, try this textbox1.text = string.format("{0:G}",datetime.now); or visit this http://codeincsharp.blogspot.com/2008/05/different-date-format-in-c.html Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.

                    modified on Tuesday, April 28, 2009 3:07 AM

                    A Offline
                    A Offline
                    Abhijit Jana
                    wrote on last edited by
                    #9

                    Your post is breaking the formatting. Please post the link properly. Thank you.

                    cheers, Abhijit CodeProject MVP

                    1 Reply Last reply
                    0
                    • C CrazyCoder26

                      Hi, I have developed an web page.In which there is a textbox for date entry and the entry format is dd/MM/yyyy. Somewhere in my code I am converting this textbox value to datetime.e.g: Datetime myDt=Convert.ToDateTime(textbox1.Text); This works fine in my local PC.But when I uploaded this page on server it threw the following error: "String was not recognized as a valid DateTime". Can anyone help me out!! Thnaks and regards

                      ARINDAM

                      K Offline
                      K Offline
                      Kaushal Arora
                      wrote on last edited by
                      #10

                      Hi, Try using this code, this is a bit lengthy work but is useful in these type of cases. // First Split the Textbox text on '/' string[] arrdate = textbox1.Text.Split('/'); //Get the Splitted values in variable, You can also use them directly in the followed statement used to create DateTime. int year = Convert.ToInt32(arrdate[2].ToString()); int month = Convert.ToInt32(arrdate[1].ToString()); int day = Convert.ToInt32(arrdate[0].ToString()); // Now create a new Datetime variable DateTime myDt = new DateTime(year, month, day); // Or you can write like this DateTime myDt = new DateTime(Convert.ToInt32(arrdate[2].ToString()), Convert.ToInt32(arrdate[1].ToString()), Convert.ToInt32(arrdate[0].ToString())); // Here is you Datetime variable. Regards, Kaushal Arora Please mark as Answer if it solved your problem.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups