Export (0) Print
Expand All

DateTime.Date Property

Gets the date component of this instance.

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

'Declaration
Public ReadOnly Property Date As DateTime

Property Value

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

The value of the Kind property of the returned DateTime value is the same as that of the current instance.

Because the DateTime type represents both dates and times in a single type, it is important to avoid misinterpreting a date returned by the Date property as a date and time.

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.

Dim date1 As Date = #6/1/2008 7:47AM#
Console.WriteLine(date1.ToString())

' Get date-only portion of date, without its time. 
Dim dateOnly As Date = date1.Date 
' Display date using short date string.
Console.WriteLine(dateOnly.ToString("d"))
' Display date using 24-hour clock.
Console.WriteLine(dateOnly.ToString("g"))
Console.WriteLine(dateOnly.ToString("MM/dd/yyyy HH:mm"))   
' The example displays the following output to the console: 
'       6/1/2008 7:47:00 AM 
'       6/1/2008 
'       6/1/2008 12:00 AM 
'       06/01/2008 00:00

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft