How to display "from" inside the Datetimepicker

Asked

Viewed 240 times

2

In the DateTimePicker I can display anything using d to day, MM or MMMM for month and yy or yyyy to year.

However, I would simply like to display on the property customformat: April 15.

But when I write:

dtApartir.CustomFormat = "d de MMMM de yyyy";

Results in:

15 15th April 15th 2014.

Is there any way around that and display the "d" of the "of"?

3 answers

2


Use simple quotes inside the string, as if they were substrings:

dtApartir.CustomFormat = "d' de 'MMMM' de 'yyyy";
  • It worked, so release milestone as sure (:

0

Use the barra invertida \\.

To prevent a character from being interpreted as a specifier format, you can precede it with a backslash \\, which is the escape character.

The escape character means that the following is a literal character that must be included in the result sequence unchanged.

Do so:

 dtApartir.CustomFormat = "d \\de MMMM \\de yyyy";
  • Returned Error: Unrecognized Escape Quence

  • 1

    To use this solution, you would have to do so: @"d \de MMMM \de yyyy", or else "d \\de MMMM \\de yyyy".

0

This happens because C# interprets the letter’d' of the word "from" as if it were the letter 'd' reserved for the day number format.

Don’t forget to set the Format, also:

dtApartir.CustomFormat = String.Format("d {0} MMMM {0}", "'de'");
dtApartir.Format = DateTimePickerFormat.Custom;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.