Export (0) Print
Expand All

DateTime.Today Property

Updated: July 2008

Gets the current date.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static DateTime Today { get; }

Property Value

Type: System.DateTime
A DateTime set to today's date, with the time component set to 00:00:00.

Starting with the .NET Framework version 2.0, the return value is a DateTime whose Kind property returns Local.

Because it returns the current date without the current time, the Today property is suitable for use in applications that work with dates only. For details, see Choosing Between DateTime, DateTimeOffset, and TimeZoneInfo. In contrast, the TimeOfDay property returns the current time without the current date, and the Now property returns both the current date and the current time.

The following example uses the Date property to retrieve the current date. It also illustrates how a DateTime value can be formatted using some of the standard date and time format strings. Note that the output produced by the third call to the ToString(String) method uses the "g" format specifier to include the time component, which is zero.

// Get current date.
DateTime thisDay = DateTime.Today;
// Display the date in a variety of formats.
Console.WriteLine(thisDay.ToString("d"));
Console.WriteLine(thisDay.ToString("D"));
Console.WriteLine(thisDay.ToString("g"));

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Date

History

Reason

July 2008

Added usage details and an example.

Customer feedback.

Community Additions

ADD
Show:
© 2014 Microsoft