DateTimeFormatInfo.ShortDatePattern Property

Updated: December 2010

Gets or sets the format pattern for a short date value, which is associated with the "d" format pattern.

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

public string ShortDatePattern { get; set; }

Property Value

Type: System.String
The format pattern for a short date value, which is associated with the "d" format pattern.

ExceptionCondition
ArgumentNullException

The property is being set to null.

InvalidOperationException

The property is being set and the DateTimeFormatInfo object is read-only.

See Custom Date and Time Format Strings for patterns that can be combined to construct custom patterns, for example, "MM/dd/yyyy".

This property is affected if the value of the Calendar property changes.

The DateSeparator property is derived from the ShortDatePattern property. You should set the short date pattern to the exact value of interest, instead of attempting to have the date separator replaced. For example, to obtain the pattern MM-DD-yyyy, you should explicitly set the short date pattern to "MM-DD-yyyy". This also permits you to setting a pattern such as "MM/DD, yyyy" that does not contain a traditional separator between all parts of the format.

The following example displays the value of the ShortDatePattern property and the value of a date formatted using the ShortDatePattern property for a few cultures.

using System;
using System.Globalization;

public class SamplesDTFI  
{
   public static void Main()  
   {
      string[]  cultures = { "en-US", "ja-JP", "fr-FR" };
      DateTime date1 = new DateTime(2011, 5, 1);

      Console.WriteLine(" {0,7} {1,19} {2,10}\n", "CULTURE", "PROPERTY VALUE", "DATE");

      foreach (var culture in cultures) {
         DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture(culture).DateTimeFormat;
         Console.WriteLine(" {0,7} {1,19} {2,10}", culture, 
                           dtfi.ShortDatePattern, 
                           date1.ToString("d", dtfi));
      }
   }
}
// The example displays the following output: 
//        CULTURE      PROPERTY VALUE       DATE 
//        
//          en-US            M/d/yyyy   5/1/2011 
//          ja-JP          yyyy/MM/dd 2011/05/01 
//          fr-FR          dd/MM/yyyy 01/05/2011

The following example modifies the ShortDatePattern property of a DateTimeFormatInfo object that represents the formatting conventions of the English (United States) culture. It also displays a date value twice, first to reflect the original ShortDatePattern property and then to reflect the new property value.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat;
      DateTime date1 = new DateTime(2011, 5, 1);
      Console.WriteLine("Original Short Date Pattern:");
      Console.WriteLine("   {0}: {1}", dtfi.ShortDatePattern, 
                                       date1.ToString("d", dtfi));
      dtfi.DateSeparator = "-";
      dtfi.ShortDatePattern = @"yyyy/MM/dd";
      Console.WriteLine("Revised Short Date Pattern:");
      Console.WriteLine("   {0}: {1}", dtfi.ShortDatePattern, 
                                       date1.ToString("d", dtfi));
   }
}
// The example displays the following output: 
//       Original Short Date Pattern: 
//          M/d/yyyy: 5/1/2011 
//       Revised Short Date Pattern: 
//          yyyy/MM/dd: 2011-05-01

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.

.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

Date

History

Reason

December 2010

Revised the first example and added the second example.

Customer feedback.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft