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. General Programming
  3. C#
  4. DateTime.TryParse() - what is the defined behaviour?

DateTime.TryParse() - what is the defined behaviour?

Scheduled Pinned Locked Moved C#
question
6 Posts 3 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.
  • N Offline
    N Offline
    Neophyte30
    wrote on last edited by
    #1

    I'm currently using DateTime.TryParse() on a text field with the format DD/MM/YY. I noticed that the default behaviour of TryParse() was rather fortuitously turning 08 into 2008. Which got me thinking (apart from - next time I'll use a field with YYYY) - how does TryParse decide which century to use? I can't find anything on MSDN, and an initial Google search turned up nothing. Can anyone satisfy my curiosity and tell me the "rules" that are used? My gut feeling is that it's tucked away in the Culture settings somehow...

    P 1 Reply Last reply
    0
    • N Neophyte30

      I'm currently using DateTime.TryParse() on a text field with the format DD/MM/YY. I noticed that the default behaviour of TryParse() was rather fortuitously turning 08 into 2008. Which got me thinking (apart from - next time I'll use a field with YYYY) - how does TryParse decide which century to use? I can't find anything on MSDN, and an initial Google search turned up nothing. Can anyone satisfy my curiosity and tell me the "rules" that are used? My gut feeling is that it's tucked away in the Culture settings somehow...

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Why not download Reflector and find out for yourself? This is a fantastic tool that is invaluable if you want to find out how things work rather than just accepting that they do.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      L 1 Reply Last reply
      0
      • P Pete OHanlon

        Why not download Reflector and find out for yourself? This is a fantastic tool that is invaluable if you want to find out how things work rather than just accepting that they do.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        looking at one implementation rather than reading the documentation[^] :confused:

        Luc Pattyn [Forum Guidelines] [My Articles]


        This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


        P N 2 Replies Last reply
        0
        • L Luc Pattyn

          looking at one implementation rather than reading the documentation[^] :confused:

          Luc Pattyn [Forum Guidelines] [My Articles]


          This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Luc Pattyn wrote:

          looking at one implementation rather than reading the documentation[^]

          More a general hint that there are other options. Sure - read the documentation, but don't accept that it's right - actually research for yourself. After all, the MSDN is well known for its accuracy and consistency. :-D

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          1 Reply Last reply
          0
          • L Luc Pattyn

            looking at one implementation rather than reading the documentation[^] :confused:

            Luc Pattyn [Forum Guidelines] [My Articles]


            This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


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

            Thanks for taking the time to have a look - I didn't find/see a link to this documentation in the msdn documentation on TryParse(), but unfortunately this documentation doesn't answer my initial question. When I get a little time today, I will attempt to follow Mr O'Hanlon's suggestion. (I have avoided Reflector in the past as it seemed a bit scary) :)

            L 1 Reply Last reply
            0
            • N Neophyte30

              Thanks for taking the time to have a look - I didn't find/see a link to this documentation in the msdn documentation on TryParse(), but unfortunately this documentation doesn't answer my initial question. When I get a little time today, I will attempt to follow Mr O'Hanlon's suggestion. (I have avoided Reflector in the past as it seemed a bit scary) :)

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Neophyte30 wrote:

              I didn't find/see a link to this documentation

              DateTime.TryParse() has an overload that takes a IFormatProvider parameter and puts you in charge of what is acceptable and what is not. :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


              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