This is a migrated thread and some comments may be shown as answers.

Change DatePicker Date Format

3 Answers 846 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Shehnaz
Top achievements
Rank 1
Shehnaz asked on 27 May 2011, 03:26 PM
Hi...
Can u tell me way where i can change the Date format of the control in XAML. I m following MVVM pattern. Is dere any inbuilt property by which we can directly change d date format...???
Plz reply ASAP.
Thanx n regards
Shehnaz Khan.

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 01 Jun 2011, 08:45 AM
Hello Shehnaz,

Please check this help article which explains how the date can be formatted in RadDateTimePicker. Unfortunately, you can define a custom format only in code-behind.

Regards,
Yana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vinod
Top achievements
Rank 1
answered on 04 Jan 2012, 04:00 PM

We have used cultute info to rad datepicker using the folloing code:
            CultureInfo ldtPckrcultureInfo = new CultureInfo("en-US");
            DateTimeFormatInfo dateInfo = new DateTimeFormatInfo();
            dateInfo.ShortDatePattern = "MM-dd-yy";
            ldtPckrcultureInfo.DateTimeFormat = dateInfo;
            dtpStartDate.Culture = ldtPckrcultureInfo;

This was working fine.
But when we try to enter date manually into the date picker, the order of month, day and year gets changed.
On manually adding the date value in date picker, it takes the date in the different format (dd-yy-mm)
For example, if we enter 04-06-12 (6th April 2012), it becomes 12-06-04 (12th June 2004).
If we enter 04-15-12 (15th April 2012), we get error.

If we change an existing value, suppose,  01-11-12  to 01-10-12 , it becomes 10-12-01 .


0
Ivo
Telerik team
answered on 06 Jan 2012, 01:37 PM
Hi,

The DateTimeFormat.DateSeparator property is the key to resolving this issue. If you set it to "-" your code should work great. However I would recommend you not to create a new instance of DateTimeFormat class, because this will cause the RadDateTimePicker to be in invariant culture . Here is the recommended code for your scenario:
this.RadDateTimePicker.Culture = new CultureInfo("en-US");
this.RadDateTimePicker.Culture.DateTimeFormat.ShortDatePattern = "MM-dd-yy";
this.RadDateTimePicker.Culture.DateTimeFormat.DateSeparator = "-";

All the best,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DatePicker
Asked by
Shehnaz
Top achievements
Rank 1
Answers by
Yana
Telerik team
Vinod
Top achievements
Rank 1
Ivo
Telerik team
Share this question
or