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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Is Someone aware of this Error?

Is Someone aware of this Error?

Scheduled Pinned Locked Moved C#
helpdatabasequestion
10 Posts 4 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.
  • J Offline
    J Offline
    just4ulove7
    wrote on last edited by
    #1

    Hi.. I am getting this Error while DateTime.Parse(txtActStartDate.ToString()) where the textbox contains - 31-01-2004 -- in dd-MM-yyyy format The string was not recognized as a valid DateTime. There is a unknown word starting at index 0. Whats the problem? Thanks

    A G 2 Replies Last reply
    0
    • J just4ulove7

      Hi.. I am getting this Error while DateTime.Parse(txtActStartDate.ToString()) where the textbox contains - 31-01-2004 -- in dd-MM-yyyy format The string was not recognized as a valid DateTime. There is a unknown word starting at index 0. Whats the problem? Thanks

      A Offline
      A Offline
      Alomgir Miah
      wrote on last edited by
      #2

      Please use the overloaded Parse method DateTime.Parse Method (String, IFormatProvider, DateTimeStyles) and specify the Format.

      J 1 Reply Last reply
      0
      • J just4ulove7

        Hi.. I am getting this Error while DateTime.Parse(txtActStartDate.ToString()) where the textbox contains - 31-01-2004 -- in dd-MM-yyyy format The string was not recognized as a valid DateTime. There is a unknown word starting at index 0. Whats the problem? Thanks

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Please stop double posting. I just answered this question in the asp.net section. --- b { font-weight: normal; }

        1 Reply Last reply
        0
        • A Alomgir Miah

          Please use the overloaded Parse method DateTime.Parse Method (String, IFormatProvider, DateTimeStyles) and specify the Format.

          J Offline
          J Offline
          just4ulove7
          wrote on last edited by
          #4

          I used .. Convert.ToDateTime("31/01/2004",new CultureInfo("en-GB")) But still getting the same error, I want to specify British Date Style.. ??? Thanks

          G D 2 Replies Last reply
          0
          • J just4ulove7

            I used .. Convert.ToDateTime("31/01/2004",new CultureInfo("en-GB")) But still getting the same error, I want to specify British Date Style.. ??? Thanks

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            It works just fine when I try it. Does your code look exactly like that? --- b { font-weight: normal; }

            J 1 Reply Last reply
            0
            • G Guffa

              It works just fine when I try it. Does your code look exactly like that? --- b { font-weight: normal; }

              J Offline
              J Offline
              just4ulove7
              wrote on last edited by
              #6

              Hi, I have set the date value in the text box. I am trying to save in this way... Convert.ToDateTime(txtname.Text,new CultureInfo("en-GB")).. txtname contains 31/03/2004 This is throwing the same error. But again I hard-code the value of txtname.text with Convert.ToDateTime("31/03/2004",new CultureInfo("en-GB")) Its working fine.. What cud be the problem with the textbox? Thanks

              G 1 Reply Last reply
              0
              • J just4ulove7

                I used .. Convert.ToDateTime("31/01/2004",new CultureInfo("en-GB")) But still getting the same error, I want to specify British Date Style.. ??? Thanks

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                That's because your using the Convert class. Use the DateTime Parse method to do this:

                DateTime newDate = **DateTime.Parse**("31/01/2004", new CultureInfo("en-GB"));
                

                or

                DateTime newDate = **DateTime.Parse**("31/01/2004", "dd/MM/yyyy", Application.CurrentCulture.DateTimeFormat);
                

                also works. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                J 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  That's because your using the Convert class. Use the DateTime Parse method to do this:

                  DateTime newDate = **DateTime.Parse**("31/01/2004", new CultureInfo("en-GB"));
                  

                  or

                  DateTime newDate = **DateTime.Parse**("31/01/2004", "dd/MM/yyyy", Application.CurrentCulture.DateTimeFormat);
                  

                  also works. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  J Offline
                  J Offline
                  just4ulove7
                  wrote on last edited by
                  #8

                  Thanks a lot, its working fine.. But wats the diff between Convert and DateTime class for this. It was working with a hardcoded string and not with a textbox?

                  D 1 Reply Last reply
                  0
                  • J just4ulove7

                    Hi, I have set the date value in the text box. I am trying to save in this way... Convert.ToDateTime(txtname.Text,new CultureInfo("en-GB")).. txtname contains 31/03/2004 This is throwing the same error. But again I hard-code the value of txtname.text with Convert.ToDateTime("31/03/2004",new CultureInfo("en-GB")) Its working fine.. What cud be the problem with the textbox? Thanks

                    G Offline
                    G Offline
                    Guffa
                    wrote on last edited by
                    #9

                    Have you tried to write out the value from the text box, so that you are sure that it is sent to the server correctly? --- b { font-weight: normal; }

                    1 Reply Last reply
                    0
                    • J just4ulove7

                      Thanks a lot, its working fine.. But wats the diff between Convert and DateTime class for this. It was working with a hardcoded string and not with a textbox?

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #10

                      When you're converting a string to any kind of object, if the object has a Parse method, use it. IMHO, it's always going to work better than the more generic methods in Convert. Also, Parse deals with whitespace and invalid character issues better. I've almost gotten away with never using Convert in any of my apps... There is no difference between a TextBox's Text property and a String. The Text property returns a String object, so, the only possible problem is an input error in the TextBox. If you include leading and/or trailing spaces, tabs, incorrect formatting characters, ..., Convert might not work whereas Parse might. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                      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