views:

260

answers:

3

I am developing a C# application where user can select any date time format and display in date time picker.How to change the format of date time picker in code?

+5  A: 

If you want to set your own custom format, you can set the following two properties of your Date Time Picker control to achieve this:

dateTimePicker1.CustomFormat = "yyyy mm ddd";
dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;

Obviously, you can replace "yyyy mm ddd" with any valid date format string.

CraigTP
A: 

You can go here DateTimePicker and here to get the format of definitions DateTimePicker CustomFormat

Khan
A: 

use capital M for month ...

dateTimePicker1.CustomFormat = "yyyy MM ddd"; dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;

AmiT