DateTime.Date Property

July 28, 2014

Gets the date component of this instance.

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

public DateTime Date { get; }

Property Value

Type: System.DateTime
A new object that has the same date as this instance, and its time value set to 12:00:00 midnight (00:00:00).

The following example uses the Date property to extract the date component of a DateTime value with its time component set to zero (or 0:00:00, or midnight). It also illustrates that, depending on the format string used when displaying the DateTime value, the time component can continue to appear in formatted output.


DateTime date1 = new DateTime(2008, 6, 1, 7, 47, 0);
outputBlock.Text += date1.ToString() + "\n";

// Get date-only portion of date, without its time.
DateTime dateOnly = date1.Date;
// Display date using short date string.
outputBlock.Text += dateOnly.ToString("d") + "\n";
// Display date using 24-hour clock.
outputBlock.Text += dateOnly.ToString("g") + "\n";
outputBlock.Text += dateOnly.ToString("MM/dd/yyyy HH:mm") + "\n";
// The example displays the following output:
//       6/1/2008 7:47:00 AM
//       6/1/2008
//       6/1/2008 12:00 AM
//       06/01/2008 00:00


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft