Date Formatting in WPF DatePicker (SfDatePicker)

14 Mar 20241 minute to read

The SfDatePicker control allows the user to select and display the date in various formats.

Display the date using the FormatString

We can edit and display the selected date with various formatting like date, month and year formats by using the FormatString property. The default value of FormatString property is "d".

<syncfusion:SfDatePicker x:Name="sfDatePicker" 
                         FormatString="M"/>
SfDatePicker sfDatePicker = new SfDatePicker();
sfDatePicker.FormatString = "M";

WPF DatePicker FormatString

Specifying format for the DateSelector

We can allow the user to select the pair of date, month and year selector or any single selector cell from the SfDateSelector by using the SelectorFormatString property. The default value of SelectorFormatString property is "M/d/yyyy" and the date, time and year value selector is enabled in the SfDateSelector.

<syncfusion:SfDatePicker x:Name="sfDatePicker" 
                         SelectorFormatString="M"/>
SfDatePicker sfDatePicker = new SfDatePicker();
sfDatePicker.SelectorFormatString = "M";

WPF DatePicker Month Selector

Here, we can only able to select the month value from the SfDateSelector

Click here to download the sample that showcases the edit, display date formatting and date selection formatting by the SfDatePicker.

NOTE

A detailed explanation of standard date time formatting is available here. The result string produced by these format specifiers are influenced by the settings in the Regional Options control panel. Computers with different cultures or different date and time settings will generate different result strings.