Skip to main content
All docs
V24.2

Mask Type: Date Only

  • 4 minutes to read

The DateOnly masks work similar to Date-Time masks and change the editor’s EditValue property type to DateOnly.

DateOnly Mask Example

DateOnly Mask Modes

The DevExpress WPF Data Editors support the following input modes for DateOnly masks:

  • DateOnly - supports only manual navigation between editable mask parts.
  • DateOnlyAdvancingCaret - enables automatic navigation between mask parts. If a user completes a part of the value, the caret moves to the next editable part.

Enable DateOnly Masks

To enable a particular DateOnly mask mode, set the TextEdit.MaskType property (or the TextEditSettings.MaskType for in-place editors) to DateOnly or DateOnlyAdvancingCaret. Use the TextEdit.Mask property (or TextEditSettings.Mask for in-place editors) to specify the mask itself.

Mask as a Display Format

DateOnly masks are similar to the display formats described in the Date and Time Format Strings document. You can use the editor’s mask as a display format specifier. If an editor loses input focus, the display text still uses the specified custom format. To enable this functionality, use the TextEdit.MaskUseAsDisplayFormat property (TextEditSettings.MaskUseAsDisplayFormat for in-place editors).

Predefined Masks

Predefined masks allow users to edit DateOnly values according to common patterns. The table below lists the available masks.

Standard Mask Name Description Samples Culture: English (U.S.)
d Short date The mask matches the pattern specified by the ShortDatePattern property. CD_Mask_DateTime_d-short
D Long date The mask matches the pattern specified by the LongDatePattern property. CD_Mask_DateTime_D-long
M or m Month day The mask matches the pattern specified by the MonthDayPattern property. CD_Mask_DateTime_M
Y or y Year month The mask matches the pattern specified by the YearMonthPattern property. CD_Mask_DateTime_Y

Custom Masks

Use the following mask specifiers to create custom DateOnly masks:

Mask Specifier

Description

Sample

d

A day of a month.

1 - 31

dd

A day of a month, starts with zero for single-digit values.

01 - 31

ddd

A read-only abbreviated name of the day of the week.

The AbbreviatedDayNames property returns abbreviated day names for the current culture.

Sun - Sat

dddd

A read-only name of the day of the week.

The DayNames property returns day names for the current culture.

Sunday - Saturday

g

A read-only era.

The Eras property returns era names for the current calendar.

AD, CE

M

A month number.

1 - 12

MM

A month number, starts with zero for single-digit values.

01-12

MMM

An abbreviated name of the month.

The AbbreviatedMonthNames property returns abbreviated month names for the current culture.

Jan - Dec

MMMM

A name of the month.

The MonthNames property returns month names for the current culture.

January - December

y

Last two digits of the year.

1 for 2001, 30 for 1930

yy

Last two digits of the year, starts with zero for single-digit values.

01 for 2001, 30 for 1930

yyyy

A four-digit year.

0001-9999

/

A date separator.

The DateSeparator property returns the date separator for the current culture.

/ in the en-US culture

\

The escape character that allows you to insert a following character as a text.

\M\M is interpreted as a MM text

' or "

A read-only custom string.

‘Current date:’

If you use a mask specifier as a single character, it is interpreted as a predefined mask. To use a custom specifier which matches one of the standard specifiers, precede this specifier with the % character (%d).

User Capabilities

  • The Up Arrow and Down Arrow keys increase and decrease the focused part of the date value.
  • The mouse wheel increases and decreases the focused part of the date value.
  • Users can enter the initial letter of the month or the month’s order number (1-12) to edit the full or abbreviated month name.
  • The Space key moves the caret to the next part of the date value.
  • The date separator character moves the caret to the next part of the date value.
  • The Left Arrow and Right Arrow keys move the caret to the previous or next part of the date value.
  • If a mask requires users to enter a four digit year (the yyyy mask), a user can enter the last two (or one) digits of this year. The first two digits are determined based on the current culture.

    Refer to the following help topic for more information: TwoDigitYearMax.

Example

The following code sample binds the TextEdit to a DateOnly field and specifies an input mask:

DateOnly Mask Example

<dxe:TextEdit EditValue="{Binding DateOnlyValue}" 
              MaskType="DateOnly" Mask="yyyy-MMMM-dd dddd" 
              MaskUseAsDisplayFormat="True"/>
public class ViewModel : ViewModelBase {
    public DateOnly DateOnlyValue { get; set; } = new DateOnly(2022, 12, 22);
}