DateTimeOffset.Date Property

July 28, 2014

Gets a DateTime value that represents the date component of the current DateTimeOffset object.

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

public DateTime Date { get; }

Property Value

Type: System.DateTime
An object whose value represents the date component of the current DateTimeOffset object.

This property removes any significant part of the time component from a DateTimeOffset object and returns only its significant date component. For example, if the DateTimeOffset object has a date and time value of "1/12/07 4:01pm +7:30", the property returns a DateTime value of "1/12/07 12:00:00 AM". The DateTime value can then be displayed by using any of the standard or custom format specifiers that display dates only. (See the Example section for an illustration.)

The value of the DateTime.Kind property of the returned DateTime object is always DateTimeKind.Unspecified. It is not affected by the value of the Offset property.

To display a date without its time component, you can also use the "D" or "d" format specifiers; for an illustration, see the Example section.

The following example retrieves the value of the Date property for a specific date. It then displays that value to the console using some standard and custom date-only format specifiers.


// Illustrate Date property and date formatting
DateTimeOffset thisDate = new DateTimeOffset(2008, 3, 17, 1, 32, 0, new TimeSpan(-5, 0, 0));
string fmt;                      // format specifier

// Display date only using "D" format specifier
// For en-us culture, displays:
//   'D' format specifier: Monday, March 17, 2008
fmt = "D";
outputBlock.Text += String.Format("'{0}' format specifier: {1}",
                  fmt, thisDate.Date.ToString(fmt)) + "\n";

// Display date only using "d" format specifier
// For en-us culture, displays:
//   'd' format specifier: 3/17/2008
fmt = "d";
outputBlock.Text += String.Format("'{0}' format specifier: {1}",
                  fmt, thisDate.Date.ToString(fmt)) + "\n";

// Display date only using "Y" (or "y") format specifier
// For en-us culture, displays:
//   'Y' format specifier: March, 2008
fmt = "Y";
outputBlock.Text += String.Format("'{0}' format specifier: {1}",
                  fmt, thisDate.Date.ToString(fmt)) + "\n";

// Display date only using custom format specifier
// For en-us culture, displays:
//   'dd MMM yyyy' format specifier: 17 Mar 2008
fmt = "dd MMM yyyy";
outputBlock.Text += String.Format("'{0}' format specifier: {1}",
                  fmt, thisDate.Date.ToString(fmt)) + "\n";


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft