C# DateTime Methods

About This Index
This page is the C# DateTime Methods index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs. All examples use fixed dates such as new DateTime(2026, 11, 18), so the output you see is the output you get.
Learn what DateTime is for on /c-sharp/datetime. Use this page when you need a specific API such as AddDays(), TryParse(), or ToString().
dt.AddDays(1) does not change dt. It returns a new value, so write dt = dt.AddDays(1) when you want to keep the result. Also remember Kind: a DateTime can be Utc, Local, or Unspecified.
How to Call a DateTime Method
Most methods are called on a value (dt.AddDays(7)). A few are static and use the type name (DateTime.TryParse(...)):
DateTime dt = new DateTime(2026, 11, 18);
DateTime next = dt.AddDays(7); // instance
bool ok = DateTime.TryParse("2026-12-25", out DateTime x); // static
int days = DateTime.DaysInMonth(2026, 11); // static
string text = dt.ToString("yyyy-MM-dd"); // instance C# DateTime Methods Table
All method guides in this C# tutorial series (38 tutorials), grouped by purpose.
Add / subtract
10 methodsMove a DateTime forward or back by days, hours, months, years, ticks, or a TimeSpan. Every call returns a new DateTime.
| Method | Description | Tutorial |
|---|---|---|
Add() | Add a TimeSpan to a DateTime and get a new DateTime back. | Try it |
AddDays() | Add or subtract a number of days and get a new DateTime. | Try it |
AddHours() | Add or subtract hours (including fractions) and get a new DateTime. | Try it |
AddMilliseconds() | Add or subtract milliseconds and get a new DateTime. | Try it |
AddMinutes() | Add or subtract minutes and get a new DateTime. | Try it |
AddMonths() | Add or subtract whole months; the day is clamped when the target month is shorter. | Try it |
AddSeconds() | Add or subtract seconds (fractions allowed) and get a new DateTime. | Try it |
AddTicks() | Add or subtract raw ticks (100 ns steps) and get a new DateTime. | Try it |
AddYears() | Add or subtract whole years; Feb 29 becomes Feb 28 in a non-leap year. | Try it |
Subtract() | Subtract a DateTime to get a TimeSpan, or subtract a TimeSpan to get a DateTime. | Try it |
Compare
4 methodsOrder two dates, test equality, and read a hash code for dictionaries and sets.
| Method | Description | Tutorial |
|---|---|---|
Compare() | Compare two DateTime values and get a number: less than, equal to, or greater than zero. | Try it |
CompareTo() | Compare this DateTime to another value and get less than, equal to, or greater than zero. | Try it |
Equals() | Check if two DateTime values are the same instant (same ticks). | Try it |
GetHashCode() | Get an int hash code for a DateTime, used by HashSet and Dictionary. | Try it |
Calendar info
3 methodsAsk how many days a month has, whether a year is a leap year, or whether a time falls in daylight saving time.
| Method | Description | Tutorial |
|---|---|---|
DaysInMonth() | Get the number of days in a month for a given year (28, 29, 30, or 31). | Try it |
IsLeapYear() | Check if a year is a leap year (true or false). | Try it |
IsDaylightSavingTime() | Check if a DateTime falls in daylight saving time for the local time zone. | Try it |
Parsing
4 methodsTurn text into DateTime with Parse, ParseExact, and the safer TryParse helpers.
| Method | Description | Tutorial |
|---|---|---|
Parse() | Convert date text to a DateTime; throws if the text is not a valid date. | Try it |
ParseExact() | Convert text to a DateTime only if it matches one exact format; throws otherwise. | Try it |
TryParse() | Try to convert date text to a DateTime; returns true or false instead of throwing. | Try it |
TryParseExact() | Try to convert text that matches an exact format; returns true or false instead of throwing. | Try it |
Formatting
6 methodsTurn a DateTime into text with ToString, short and long date or time strings, and GetDateTimeFormats.
| Method | Description | Tutorial |
|---|---|---|
ToString() | Turn a DateTime into text with a format string and an optional culture. | Try it |
ToShortDateString() | Get the date part as short text using the current culture's short date pattern. | Try it |
ToLongDateString() | Get the date part as long text with weekday and month name, using the current culture. | Try it |
ToShortTimeString() | Get the time of day as short text (hours and minutes) in the current culture. | Try it |
ToLongTimeString() | Get the time of day as long text (hours, minutes, seconds) in the current culture. | Try it |
GetDateTimeFormats() | Return many string forms of a DateTime, for all or one standard format letter. | Try it |
Time zone / kind
3 methodsWork with DateTimeKind (Utc, Local, Unspecified) and convert between local and universal time.
| Method | Description | Tutorial |
|---|---|---|
SpecifyKind() | Create a DateTime with the same ticks but a different Kind (Utc, Local, or Unspecified). | Try it |
ToLocalTime() | Convert a UTC DateTime to local time; the result has Kind Local. | Try it |
ToUniversalTime() | Convert local time to UTC; the result has Kind Utc. | Try it |
Numeric forms
8 methodsStore or exchange a date as a number: binary value, Windows file time, or OLE Automation date.
| Method | Description | Tutorial |
|---|---|---|
FromBinary() | Rebuild a DateTime from the 64-bit number made by ToBinary. | Try it |
ToBinary() | Turn a DateTime into one 64-bit number that holds both ticks and Kind. | Try it |
FromFileTime() | Convert a Windows file time number to a DateTime in local time. | Try it |
FromFileTimeUtc() | Convert a Windows file time number to a DateTime in UTC. | Try it |
ToFileTime() | Convert a DateTime (treated as local time) to a Windows file time number. | Try it |
ToFileTimeUtc() | Convert a DateTime to a Windows file time number without a local-time shift for Unspecified values. | Try it |
FromOADate() | Convert an OLE Automation date (a double, used by Excel and COM) to a DateTime. | Try it |
ToOADate() | Convert a DateTime to an OLE Automation date (a double used by Excel and COM). | Try it |
Frequently Asked Questions
Start with AddDays()
Move a date forward or back by a number of days. It is the DateTime call beginners use most often.
12 people found this page helpful
