DateTime..::.Date Property Home
This page is specific to:.NET Framework Version:1.12.03.03.5Silverlight 34.0
.NET Framework Class Library
DateTime..::.Date Property

Gets the date component of this instance.

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

'Usage

Dim instance As DateTime
Dim value As DateTime

value = instance.Date


'Declaration

Public ReadOnly Property Date As DateTime

Property Value

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

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


Platforms

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.
Version Information

.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
See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View