Skip to content

Incomplete documentation on DateTime.TryParseExact #10886

Closed
@Emberfire

Description

@Emberfire

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy