C# DateTime Methods

Beginner
6 min read
Updated: Nov 2026
38 method guides
Method index

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

DateTime is immutable.

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

C#
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 methods

Move a DateTime forward or back by days, hours, months, years, ticks, or a TimeSpan. Every call returns a new DateTime.

MethodDescriptionTutorial
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 methods

Order two dates, test equality, and read a hash code for dictionaries and sets.

MethodDescriptionTutorial
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 methods

Ask how many days a month has, whether a year is a leap year, or whether a time falls in daylight saving time.

MethodDescriptionTutorial
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 methods

Turn text into DateTime with Parse, ParseExact, and the safer TryParse helpers.

MethodDescriptionTutorial
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 methods

Turn a DateTime into text with ToString, short and long date or time strings, and GetDateTimeFormats.

MethodDescriptionTutorial
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 methods

Work with DateTimeKind (Utc, Local, Unspecified) and convert between local and universal time.

MethodDescriptionTutorial
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 methods

Store or exchange a date as a number: binary value, Windows file time, or OLE Automation date.

MethodDescriptionTutorial
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

They are the methods on System.DateTime that add or subtract time, compare dates, parse and format text, convert between UTC and local time, and turn a date into a number such as file time or an OLE Automation date.
This index lists 38 guides: add and subtract, compare, calendar info, parsing, formatting, time zone and kind, and numeric forms.
DateTime is immutable. AddDays, AddMonths, and the other Add methods return a new DateTime. Assign the result, such as dt = dt.AddDays(1).
Use TryParse for user input because it returns false instead of throwing. Use ParseExact or TryParseExact when the text must match one exact format, such as dd-MM-yyyy.
Read the C# DateTime hub first. Then open AddDays(), TryParse(), ToString(), and Subtract() from the tables below.

Start with AddDays()

Move a date forward or back by a number of days. It is the DateTime call beginners use most often.

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

12 people found this page helpful