In C#, DateTime.Parse reads a string and returns a DateTime. It understands many common date and time shapes, such as 2026-11-18 or 2026-11-18 14:30:45.
If the text cannot be read as a date, Parse throws FormatException. If you are not sure the text is valid, use TryParse instead.
This is a static member of System.DateTime. You call it with the type name, such as DateTime.Parse(...). DateTime holds a date and time of day with a Kind of Utc, Local, or Unspecified.
Syntax
Pass the text. Add a culture when the format depends on the country.
C#
DateTime a = DateTime.Parse("2026-11-18");
DateTime b = DateTime.Parse("18/11/2026", new CultureInfo("en-GB"));
DateTime c = DateTime.Parse("11/18/2026", CultureInfo.InvariantCulture);
Call
What it does
DateTime.Parse("2026-11-18")
ISO-style text works in every culture.
DateTime.Parse(text, culture)
Read text using the date rules of a culture.
DateTime.Parse(text, culture, styles)
Add DateTimeStyles such as AssumeUniversal.
Without a culture, Parse uses the computer's current culture. The text 03/04/2026 can mean March 4 or April 3. For input from users or files, always pass a culture.
Library declarations
C#
public static DateTime Parse(string s);
public static DateTime Parse(string s, IFormatProvider? provider);
public static DateTime Parse(string s, IFormatProvider? provider, DateTimeStyles styles);
Parameters
Parameter
Description
s
Required. The text to read. Must not be null.
provider
Optional. A CultureInfo (or other provider) with the date rules to use. Default is the current culture.
styles
Optional. DateTimeStyles flags that change how the text is read.
Return Value
Return Value
Description
DateTime
The date and time read from the text. The Kind is Unspecified unless the text includes a zone.
C# Examples
Example 1 — Parse Standard Text
Read a date and a date with time from year-first text.
C#
using System;
using System.Globalization;
class Program {
static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
static void Main() {
DateTime a = DateTime.Parse("2026-11-18");
DateTime b = DateTime.Parse("2026-11-18 14:30:45");
Console.WriteLine(Show(a));
Console.WriteLine(Show(b));
}
}
Output
2026-11-18 00:00:00
2026-11-18 14:30:45
How It Works
Year first. The yyyy-MM-dd shape means the same thing in every culture.
No time given. The first value becomes midnight, 00:00:00.
With time. The second text includes hours, minutes, and seconds, and all of them are kept.
Show helper. The helper prints a fixed pattern so the output is the same on every machine.
Example 2 — Parse with a Culture
Read day-first text with en-GB and month-first text with the invariant culture.
C#
using System;
using System.Globalization;
class Program {
static string Show(DateTime d) => d.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
static void Main() {
DateTime uk = DateTime.Parse("18/11/2026", new CultureInfo("en-GB"));
DateTime inv = DateTime.Parse("11/18/2026", CultureInfo.InvariantCulture);
Console.WriteLine(Show(uk));
Console.WriteLine(Show(inv));
}
}
Output
2026-11-18 00:00:00
2026-11-18 00:00:00
How It Works
en-GB order. British English writes day, then month, then year.
Invariant order. The invariant culture writes month, then day, then year.
Same date. Different text, same result, because each call used the matching culture.
Why pass a culture. The same text can mean a different date on a machine with other settings.
Example 3 — Invalid Text and Null
See which exception Parse throws for bad text and for null.