Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / June 2004

Tip: Looking for answers? Try searching our database.

DateTime.ParseExact custom format parsing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Geoffrey Gallaway - 09 Jun 2004 17:44 GMT
From MSDN's "Parsing Date and Time Strings" doc:
 You can specify one of the standard date and time format specifiers or a
 limited combination of the custom date and time format specifiers.

Could anyone elaborate on what the "limited combination" is?

I have a date that comes from an external source and has been converted to
an integer. For instance, "10393" is "01/03/1993". I'm trying to use "Mddyy"
but ParseExact complains. I'm guessing I'm running into this "limited
combination" problem. Of course, I could just prepend a zero to the value if
it's length is less than 6 but I'd like to avoid that..

DateTime myDate = DateTime.ParseExact("10393", "Mddyy", null);

Thanks,
Geoffeg
Katy King - 16 Jun 2004 18:53 GMT
| From: geoffeg@geoffeg.org (Geoffrey Gallaway)
|
[quoted text clipped - 5 lines]
|
| DateTime myDate = DateTime.ParseExact("10393", "Mddyy", null);

This fails because ParseExact is trying to grab "10" for "M".  If you could
prepend the zero, it would work.
I expect the phrase "limited combination" was used to cover cases like this.

Katy King
CLR Base Class Libraries.
Anthony Moore - 22 Jun 2004 01:55 GMT
Yes, this is exactly what is happening. ParseExact processes its token 1
character at a time. To be able to realize that it should grab just "1"
instead of "10" when processing the "M" format, it would have to do an
extra sort of "matching pass" on the strings.

It would almost certainly not be possible to make this faster without
slowing other cases down. There would also be a slight compatability risk
if we change the rules for matching. We could add a new method or flag to
let you opt-in to this behavior. If we see this request a lot we will
consider doing it.

We are not very clear in our documentation about what will and won't work
here. In general:
1. All the custom formats of a particular culture should work through
ParseExact.
2. All formats should work if there are some sort of separators between the
tokens.
2. Fixed-with formats (e.g. "yyyy", "MM", "ss") should work even with no
separators providing you are using a gregorian calendar. Non gregorian
clandars may not work because they can have 2 or 3 digits years, which
throws the whole thing off.

Well track the feature request and see if we can improve our documentation
here. Thanks.

Anthony Moore
Base Class Libraries.

--------------------
| X-Tomcat-ID: 539727008
| References: <b027ba1c.0406090844.2074ab89@posting.google.com>
[quoted text clipped - 31 lines]
| Katy King
| CLR Base Class Libraries.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.