C# Convert ToDateTime() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Convert

Definition

In C#, Convert.ToDateTime builds a DateTime from a string or from another convertible object.

Parsing follows the current culture’s date patterns (unless you pass an IFormatProvider). Prefer DateTime.TryParse when input may be invalid.

This is a static member of System.Convert. You call it with the type name, such as Convert.ToDateTime(...). Convert is the everyday API for converting between common CLR types in C#.

Syntax

Pass a date string (and optionally a culture).

C#
DateTime d = Convert.ToDateTime("2026-11-18");
DateTime e = Convert.ToDateTime("11/18/2026");
CallWhat it does
Convert.ToDateTime("2026-11-18")Parse an ISO-like date string.
Convert.ToDateTime(obj)Convert a boxed DateTime or string.

Bad date text throws FormatException. null returns DateTime.MinValue for some overloads—prefer TryParse for clarity.

Library declarations
C#
public static DateTime ToDateTime(string? value);
public static DateTime ToDateTime(object? value);
public static DateTime ToDateTime(string? value, IFormatProvider? provider);

Parameters

ParameterDescription
valueRequired. Date text or convertible object.
providerOptional. Culture or format provider.

Return Value

Return ValueDescription
DateTimeThe parsed date and time.

C# Examples

Example 1 — Parse a Simple Date String

Convert an unambiguous year-month-day string.

C#
using System;

class Program {
    static void Main() {
        DateTime d = Convert.ToDateTime("2026-11-18");
        Console.WriteLine(d.Year);
        Console.WriteLine(d.Month);
        Console.WriteLine(d.Day);
    }
}

How It Works

  1. Year first. 2026-11-18 is easy for Convert to read.
  2. Parts. Year, Month, and Day properties match the text.
  3. Time defaults. Midnight is used when no time is present.
  4. Culture still applies. Prefer invariant/ISO forms when sharing data.

Example 2 — Include Hours and Minutes

Parse a string that has both date and time.

C#
using System;

class Program {
    static void Main() {
        DateTime d = Convert.ToDateTime("2026-11-18 14:30:00");
        Console.WriteLine(d.Hour);
        Console.WriteLine(d.Minute);
    }
}

How It Works

  1. Clock fields. Hour 14 and minute 30 come from the text.
  2. Same API. ToDateTime handles date-only and date-time strings.
  3. Local kind. Kind is typically Unspecified unless the string says otherwise.
  4. Validate input. Garbage strings throw FormatException.

Example 3 — Convert Then Format

Parse with Convert, then print a clear date.

C#
using System;

class Program {
    static void Main() {
        DateTime d = Convert.ToDateTime("2026-01-05");
        Console.WriteLine(d.ToString("yyyy-MM-dd"));
        Console.WriteLine(Convert.ToString(d.DayOfWeek));
    }
}

How It Works

  1. Parse first. Convert builds the DateTime value.
  2. Stable print. A custom format avoids culture surprises.
  3. DayOfWeek. January 5, 2026 is a Monday.
  4. ToString sibling. Convert.ToString can also print the enum name.

Frequently Asked Questions

Yes. Patterns follow the current culture unless you pass a provider.
FormatException is thrown.
Yes when user input may be wrong—TryParse returns false instead of throwing.
It produces DateTime; for offsets prefer DateTimeOffset APIs.
Similar goals. Convert also accepts object overloads used with boxed values.

Next: ToDecimal()

Convert a value to decimal—precise base-10 numbers for money and totals with System.Convert.

ToDecimal() 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.

9 people found this page helpful