user576510
user576510

Reputation: 5905

datepicker is not picking custom date format?

Requirement is to display date in the format "22 Jan 2010".

I have coded

 calanderFrom.Format = DateTimePickerFormat.Short;
 calanderFrom.CustomFormat = "dd MMM yyyy";

but date is still coming in "5/5/2011" format. Please guide me how to change fromat.

thanks

Upvotes: 4

Views: 6187

Answers (4)

FIre Panda
FIre Panda

Reputation: 6637

Replace

calanderFrom.Format = DateTimePickerFormat.Short;

with

 calanderFrom.Format = DateTimePickerFormat.Custom;

Upvotes: 13

Soner Gönül
Soner Gönül

Reputation: 98750

Use RFC1123 pattern. String.Format("{0:r}", dt);

Standard Date and Time Format Strings

Specifier DateTimeFormatInfo property Pattern value (for en-US culture)

t   ShortTimePattern    h:mm tt
d   ShortDatePattern    M/d/yyyy
T   LongTimePattern     h:mm:ss tt
D   LongDatePattern     dddd, MMMM dd, yyyy
f   (combination of D and t)    dddd, MMMM dd, yyyy h:mm tt
F   FullDateTimePattern     dddd, MMMM dd, yyyy h:mm:ss tt
g   (combination of d and t)    M/d/yyyy h:mm tt
G   (combination of d and T)    M/d/yyyy h:mm:ss tt
m, M    MonthDayPattern     MMMM dd
y, Y    YearMonthPattern    MMMM, yyyy
r, R    RFC1123Pattern  ddd, dd MMM yyyy HH':'mm':'ss 'GMT' (*)
s   SortableDateTi­mePattern    yyyy'-'MM'-'dd'T'HH':'mm':'ss (*)
u   UniversalSorta­bleDateTimePat­tern  yyyy'-'MM'-'dd HH':'mm':'ss'Z' (*)

Upvotes: 0

il_guru
il_guru

Reputation: 8508

You have to set Format to System.Windows.Forms.DateTimePickerFormat.Custom

Change your code to:

calanderFrom.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
 calanderFrom.CustomFormat = "dd MMM yyyy";

Upvotes: 0

Jay Riggs
Jay Riggs

Reputation: 53593

Don't kick yourself:

calanderFrom.Format = DateTimePickerFormat.Custom;

Use the DateTimePickerFormat.Custom value instead of DateTimePickerFormat.Short.

Upvotes: 3

Related Questions