Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete documentation on DateTime.TryParseExact #10886

Open
Emberfire opened this issue Jan 29, 2025 · 0 comments
Open

Incomplete documentation on DateTime.TryParseExact #10886

Emberfire opened this issue Jan 29, 2025 · 0 comments
Labels
area-System.DateTime untriaged New issue has not been triaged by the area owner

Comments

@Emberfire
Copy link

Type of issue

Missing information

Description

It seems the DateTime.TryParseExact method can throw a System.FormatException if the format provided is invalid. When tested in ASP.NET MVC 4.7.2, the following code:

DateTime.TryParseExact("01/10/2025", "a", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)

throws a FormatException with a stack trace:

Input string was not in a correct format
   at System.DateTimeFormat.GetRealFormat(String format, DateTimeFormatInfo dtfi)
   at System.DateTimeParse.ExpandPredefinedFormat(String format, DateTimeFormatInfo& dtfi, ParsingInfo& parseInfo, DateTimeResult& result)
   at System.DateTimeParse.DoStrictParse(String s, String formatParam, DateTimeStyles styles, DateTimeFormatInfo dtfi, DateTimeResult& result)
   at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTimeResult& result)
   at System.DateTimeParse.TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTime& result)
   at System.DateTime.TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, DateTime& result)
   ...

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.datetime.tryparseexact?view=netframework-4.7.2#system-datetime-tryparseexact(system-readonlyspan((system-char))-system-string()-system-iformatprovider-system-globalization-datetimestyles-system-datetime@)

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/DateTime.xml

Document Version Independent Id

2ba91f2f-bf41-7f7b-b0b3-64c4c0c932d9

Article author

@dotnet-bot

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.DateTime untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

1 participant