This documentation is archived and is not being maintained.

DateTimePicker.Format Property

Gets or sets the format of the date and time displayed in the control.

[Visual Basic]
Public Property Format As DateTimePickerFormat
[C#]
public DateTimePickerFormat Format {get; set;}
[C++]
public: __property DateTimePickerFormat get_Format();
public: __property void set_Format(DateTimePickerFormat);
[JScript]
public function get Format() : DateTimePickerFormat;
public function set Format(DateTimePickerFormat);

Property Value

One of the DateTimePickerFormat values. The default is Long.

Exceptions

Exception Type Condition
InvalidEnumArgumentException The value assigned is not one of the DateTimePickerFormat values.

Remarks

This property determines the date/time format the date is displayed in. The date/time format is based on the user's regional settings in their operating system.

Note   The Format property must be set to DateTimePickerFormat.Custom for the CustomFormat property to affect the formatting of the displayed date/time.

Example

[Visual Basic, C#, C++] The following example sets the CustomFormat property so that the DateTimePicker will display the date as "June 01, 2001 - Friday". This code assumes that an instance of a DateTimePicker control has been created on a Form.

[Visual Basic] 
Public Sub SetMyCustomFormat()
    ' Set the Format type and the CustomFormat string.
    dateTimePicker1.Format = DateTimePickerFormat.Custom
    dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
End Sub 'SetMyCustomFormat

[C#] 
public void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom;
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}


[C++] 
public:
void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1->Format = DateTimePickerFormat::Custom;
   dateTimePicker1->CustomFormat = S"MMMM dd, yyyy - dddd";
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DateTimePicker Class | DateTimePicker Members | System.Windows.Forms Namespace | DateTimePickerFormat

Show: