44

I have a datetimepicker which on loading of windows form shows me format in 'MM-dd-yyyy',

as follows:

enter image description here

I would like it in dd-MM-yyyy.

I tried the following:

set custom format: "dd-MM-yyyy"

But Its not changing.

What could be the problem?

Please help me.

5 Answers 5

97

Ensure that control Format property is properly set to use a custom format:

DateTimePicker1.Format = DateTimePickerFormat.Custom

Then this is how you can set your desired format:

DateTimePicker1.CustomFormat = "dd-MM-yyyy"
4
  • 4
    *both of which can be set in the properties window Commented Oct 19, 2013 at 14:04
  • 1
    @ThirdBattleOfPanipat - to use a custom format you have to set .Format AND .CustomFormat.
    – dbasnett
    Commented Oct 19, 2013 at 14:21
  • @dbasnett only dtpDate.Format.Custom option is there
    – C Sharper
    Commented Oct 19, 2013 at 14:23
  • Clean as a whistle! Commented Jun 23, 2017 at 3:45
37

Ammending as "optional Answer". If you don't need to programmatically solve the problem, here goes the "visual way" in VS2012.

In Visual Studio, you can set custom format directly from the properties Panel: enter image description here

First Set the "Format" property to: "Custom"; Secondly, set your custom format to: "dd-MM-yyyy";

1
  • this way you can also set Format to Short if the Culture Information contains the desired behavior. e.g. German Culture short will bring dd.MM.yyyy
    – LuckyLikey
    Commented Mar 16, 2017 at 8:27
12

You could easily use:

label1.Text = dateTimePicker1.Value.Date.ToString("dd/MM/yyyy")

and if you want to change '/' or '-', just add this:

label1.Text = label1.Text.Replace(".", "-")

More info about DateTimePicker.CustomFormat Property: Link

9

Try this,

string Date = datePicker1.SelectedDate.Value.ToString("dd-MMM-yyyy");

It worked for me the output format will be '02-May-2016'

3

You can set CustomFormat property to "dd-MM-yyyy" in design mode and use dateTimePicker1.Text property to fetch string in "dd/MM/yyyy" format irrespective of display format.

Not the answer you're looking for? Browse other questions tagged or ask your own question.