C# DateTime Parse() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
DateTime

Definition

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);
CallWhat 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

ParameterDescription
sRequired. The text to read. Must not be null.
providerOptional. A CultureInfo (or other provider) with the date rules to use. Default is the current culture.
stylesOptional. DateTimeStyles flags that change how the text is read.

Return Value

Return ValueDescription
DateTimeThe 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));
    }
}

How It Works

  1. Year first. The yyyy-MM-dd shape means the same thing in every culture.
  2. No time given. The first value becomes midnight, 00:00:00.
  3. With time. The second text includes hours, minutes, and seconds, and all of them are kept.
  4. 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));
    }
}

How It Works

  1. en-GB order. British English writes day, then month, then year.
  2. Invariant order. The invariant culture writes month, then day, then year.
  3. Same date. Different text, same result, because each call used the matching culture.
  4. 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.

C#
using System;

class Program {
    static void Main() {
        try {
            DateTime.Parse("hello");
        } catch (FormatException) {
            Console.WriteLine("FormatException");
        }
        string missing = null;
        try {
            DateTime.Parse(missing);
        } catch (ArgumentNullException) {
            Console.WriteLine("ArgumentNullException");
        }
    }
}

How It Works

  1. Not a date. The word hello has no date shape, so the parser gives up.
  2. FormatException. This is the standard error for text with the wrong shape.
  3. Null input. There is no string at all, which is a different problem.
  4. ArgumentNullException. Null is rejected before any parsing starts.

Frequently Asked Questions

It reads text and returns a DateTime. It throws FormatException when the text is not a valid date.
Many, such as 2026-11-18, 2026-11-18 14:30:45, and culture-specific shapes. For one exact shape, use ParseExact.
Without a culture it uses the current culture, and 03/04/2026 may mean March 4 or April 3.
Use TryParse. It returns false instead of throwing an exception.
Unspecified unless the text has a zone marker such as Z. You can change this with DateTimeStyles.

Next: ParseExact()

Convert text to a DateTime only if it matches one exact format; throws otherwise with System.DateTime.

ParseExact() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful