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");
Call
What 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
Parameter
Description
value
Required. Date text or convertible object.
provider
Optional. Culture or format provider.
Return Value
Return Value
Description
DateTime
The 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);
}
}
Output
2026
11
18
How It Works
Year first.2026-11-18 is easy for Convert to read.
Parts. Year, Month, and Day properties match the text.
Time defaults. Midnight is used when no time is present.
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);
}
}
Output
14
30
How It Works
Clock fields. Hour 14 and minute 30 come from the text.
Same API. ToDateTime handles date-only and date-time strings.
Local kind. Kind is typically Unspecified unless the string says otherwise.
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));
}
}
Output
2026-01-05
Monday
How It Works
Parse first. Convert builds the DateTime value.
Stable print. A custom format avoids culture surprises.
DayOfWeek. January 5, 2026 is a Monday.
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.