Two different mistakes, one message
- DateTime.Parse and the culture. Parse guesses the format from the current culture: the server's, or the user's in a desktop app. The same code works on a developer machine in one country and fails on a server in another. "25/12/2026" fails in en-US and works in en-GB, which puts the day first.
- DateTime.ParseExact and the format. ParseExact accepts only text that matches the format completely. A time part or a different separator makes it fail.
Parse safely
using System.Globalization;
var english = CultureInfo.GetCultureInfo("en-US");
// en-US reads month first: 25 is not a month.
Console.WriteLine(DateTime.TryParse("25/12/2026", english, DateTimeStyles.None, out _)); // prints False
Console.WriteLine(DateTime.TryParse("25/12/2026", CultureInfo.GetCultureInfo("en-GB"), DateTimeStyles.None, out _)); // prints True
// ParseExact needs the exact format: the "T10:00" part makes this fail.
Console.WriteLine(DateTime.TryParseExact("2026-12-25T10:00", "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out _)); // prints False
// Several accepted formats, one call.
string[] formats = { "yyyy-MM-dd", "yyyy-MM-dd'T'HH:mm", "dd.MM.yyyy" };
DateTime.TryParseExact("2026-12-25T10:00", formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime when);
Console.WriteLine(when.ToString("O", CultureInfo.InvariantCulture)); // prints 2026-12-25T10:00:00.0000000
To see what a format string produces for a date, and what it accepts, try the C# DateTime format tester. For Unix timestamps and ticks, use the timestamp converter.
FAQ
Why does DateTime.Parse fail for "25/12/2026"?
DateTime.Parse uses the current culture. In en-US the order is month/day/year, and 25 is not a month. In en-GB the same text is 25 December. Pass the culture you mean, or use ParseExact.
Why does ParseExact fail when the date looks right?
ParseExact requires the whole text to match the format: "2026-12-25T10:00" does not match "yyyy-MM-dd" because of the time part. Separators, the "T", seconds and fractions must all be in the format.
How do I parse dates safely?
Use DateTime.TryParseExact with the formats you accept and CultureInfo.InvariantCulture. For dates you store or exchange, use ISO 8601 (ToString("O")), which round-trips.
Has the message changed between .NET versions?
Not in our tests: .NET 6, 7, 8 and 10 all write "String '...' was not recognized as a valid DateTime." with the text quoted.