In C#, System.DateTime is the built-in type for a date and a time of day. You can build one with new DateTime(2026, 11, 18), move it with AddDays(), read text with TryParse(), and write text with ToString().
A DateTime counts time in ticks (one tick is 100 nanoseconds). It also has a Kind: Utc, Local, or Unspecified. The tutorials in this series use fixed dates so the output never changes.
This page introduces DateTime. The DateTime Methods index lists every method guide in this series.
Immutable value.
Methods such as AddDays never change the original. They return a new DateTime. If you forget to assign the result, your date will not move.
Syntax
C# Syntax
Common first steps:
C#
DateTime d1 = new DateTime(2026, 11, 18);
DateTime d2 = new DateTime(2026, 11, 18, 14, 30, 45);
DateTime d3 = d1.AddDays(7);
string text = d2.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
// DateTime.Now and DateTime.UtcNow read the clock (output changes every run)
Reference
DateTime vs DateOnly and TimeOnly
Pick the smallest type that fits your data (DateOnly and TimeOnly need .NET 6 or later):
Type
Stores
Good for
DateTime
Date and time of day, plus Kind
Timestamps, deadlines, logs
DateOnly
Calendar date only
Birthdays, holidays, due dates
TimeOnly
Time of day only
Opening hours, alarms
Code
C# Examples
Three short programs that use a fixed date.
Example 1 — Create a Date and Print It
A first program that builds a DateTime from year, month, and day, then prints parts of it.
C#
using System;
using System.Globalization;
class Program {
static void Main() {
DateTime dt = new DateTime(2026, 11, 18, 14, 30, 45);
Console.WriteLine(dt.Year);
Console.WriteLine(dt.DayOfWeek);
Console.WriteLine(dt.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture));
}
}
It is the C# struct that stores a date and a time of day. You create it with new DateTime(year, month, day) and read parts such as Year, Month, Day, and DayOfWeek.
No. DateTime is immutable. AddDays, AddMonths, and the other Add methods return a new DateTime. Assign the result to a variable to keep it.
Use DateTime when you need both date and time in one value. Use DateOnly for a calendar date only, and TimeOnly for a clock time only. Both exist in .NET 6 and later.
Kind tells you if a value is Utc, Local, or Unspecified. It matters when you convert with ToUniversalTime or ToLocalTime, and when you save or send dates.
Open the C# DateTime Methods index. It lists AddDays, Parse, TryParse, ToString, Subtract, and every other method guide.