Display Pattern in Windows Forms DateTimePicker (SfDateTimeEdit)

7 Jun 20212 minutes to read

The DateTimePattern helps you to specify the date-time display pattern for the SfDateTimeEdit. The display format of the date in the SfDateTimeEdit control can be customized by the pattern and custom display pattern properties.

DateTime format

The SfDateTimeEdit control supports the following DateTime format:

  • LongDate
  • LongTime
  • ShortDate
  • ShortTime
  • FullDateTime
  • MonthDay
  • Custom
  • ShortableDateTime
  • UniversalShortableDateTime
  • RFC1123
  • YearMonth

date time edit pattern

The different display formats of the DateTime can be set by the DateTimePattern property. The following code snippet illustrates how to set the format as LongDate:

Syncfusion.WinForms.Input.SfDateTimeEdit dateTimeEdit = new  Syncfusion.WinForms.Input.SfDateTimeEdit();

this.Controls.Add(dateTimeEdit);

dateTimeEdit.Value = new DateTime(2017, 07, 05);

dateTimeEdit.DateTimePattern = DateTimePattern.LongDate;
Dim dateTimeEdit As Syncfusion.WinForms.Input.SfDateTimeEdit = New Syncfusion.WinForms.Input.SfDateTimeEdit

Me.Controls.Add(dateTimeEdit)

dateTimeEdit.Value = New DateTime(2017, 7, 5)

dateTimeEdit.DateTimePattern = DateTimePattern.LongDate

DateTimeEdit pattern

Custom display pattern

The custom pattern can be displayed in the SfDateTimeEdit control by using the Format property. Refer to the following list to create the custom format for the SfDateTimeEdit:

  • d: Day of the month.
  • ddd: Short name of day of the week.
  • dddd: Full name of day of the week.
  • M: The month, from 1 to 12.
  • MMM: Short name of Month.
  • MMMM: Long name of the Month.
  • yy: Last two digit of year.
  • yyyy: Full Year.
  • hh: Hour.
  • mm: Minutes.
  • ss: Seconds.
  • tt: The AM/PM Meridiem.
Syncfusion.WinForms.Input.SfDateTimeEdit dateTimeEdit = new Syncfusion.WinForms.Input.SfDateTimeEdit();

this.Controls.Add(dateTimeEdit);

dateTimeEdit.Value = new DateTime(2017, 07, 05);

dateTimeEdit.DateTimePattern = DateTimePattern.Custom;

//Setting Custom Pattern

dateTimeEdit.Format = "MM/dd/yy hh:mm:ss";
Dim dateTimeEdit As Syncfusion.WinForms.Input.SfDateTimeEdit = New Syncfusion.WinForms.Input.SfDateTimeEdit

Me.Controls.Add(dateTimeEdit)

dateTimeEdit.Value = New DateTime(2017, 7, 5)

dateTimeEdit.DateTimePattern = DateTimePattern.Custom

'Setting Custom Pattern

dateTimeEdit.Format = "MM/dd/yy hh:mm:ss"

Custom date time pattern

NOTE

The CustomPattern support can be enabled by setting the DateTimePattern to the Custom.