DateTime.TryParse() - what is the defined behaviour?
-
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...
-
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...
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.
-
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.
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.
-
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.
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.
-
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.
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) :)
-
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) :)
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.