DateTime.ToShortDateString Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts the value of the current DateTime object to its equivalent short date string representation.

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

Syntax

'Declaration
Public Function ToShortDateString As String
public string ToShortDateString()

Return Value

Type: System.String
The short date string representation of the current DateTime object.

Remarks

The value of the current DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.ShortDatePattern property associated with the current thread culture. The return value is identical to the value returned by specifying the "d" standard DateTime format string with the ToString(String) method.

Important noteImportant Note:

The string returned by the ToShortDateString method is culture-sensitive. It reflects the pattern defined by the current culture's DateTimeFormatInfo object. For example, for the en-US culture, the standard short date pattern is "M/d/yyyy"; for the de-DE culture, it is "dd.MM.yyyy"; for the ja-JP culture, it is "yyyy/M/d". The specific format string on a particular computer can also be customized so that it differs from the standard short date format string.

For more information about format characters, format patterns, and the output they produce, see the Formatting Types topic. For more information about changing the format pattern associated with a format character, see the DateTimeFormatInfo class.

Examples

The following example demonstrates the ToShortDateString method. It also shows that the result of calling the ToShortDateString method is identical to calling the DateTime.ToString(String) method with "d" as the format parameter.

Imports System.Globalization
Imports System.Threading

Module Example
   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim dateToDisplay As Date = #6/1/2009 8:42:50 AM#
      Dim originalCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
      ' Change culture to en-US.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
      outputBlock.Text += String.Format("Displaying short date for {0} culture:", _
                        Thread.CurrentThread.CurrentCulture.Name) & vbCrLf
      outputBlock.Text += String.Format("   {0} (Short Date String) & vbCrLf", _
                        dateToDisplay.ToShortDateString())
      ' Display using 'd' standard format specifier to illustrate it is
      ' identical to the string returned by ToShortDateString.
      outputBlock.Text += String.Format("   {0} ('d' standard format specifier) & vbCrLf", _
                        dateToDisplay.ToString("d"))
      outputBlock.Text &= vbCrLf

      ' Change culture to fr-FR.
      Thread.CurrentThread.CurrentCulture = New CultureInfo("fr-FR")
      outputBlock.Text += String.Format("Displaying short date for {0} culture:", _
                        Thread.CurrentThread.CurrentCulture.Name) & vbCrLf
      outputBlock.Text += String.Format("   {0}", dateToDisplay.ToShortDateString()) & vbCrLf
      outputBlock.Text &= vbCrLf

      ' Change culture to nl-NL.    
      Thread.CurrentThread.CurrentCulture = New CultureInfo("nl-NL")
      outputBlock.Text += String.Format("Displaying short date for {0} culture:", _
                        Thread.CurrentThread.CurrentCulture.Name) & vbCrLf
      outputBlock.Text += String.Format("   {0}", dateToDisplay.ToShortDateString()) & vbCrLf

      ' Restore original culture.
      Thread.CurrentThread.CurrentCulture = originalCulture
   End Sub
End Module
' The example displays the following output:
'       Displaying short date for en-US culture:
'          6/1/2009 (Short Date String)
'          6/1/2009 ('d' standard format specifier)
'       
'       Displaying short date for fr-FR culture:
'          01/06/2009
'       
'       Displaying short date for nl-NL culture:
'          1-6-2009

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.