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

Display Date Format

13 Answers 1206 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
nbahl
Top achievements
Rank 1
nbahl asked on 18 Feb 2009, 03:26 PM
Hi,
Is there a way to format the display date, instead of mm/dd/yyyy I need to just display mm/yyyy.  I don't see the DisplayDateFormat property available in WPF, is there a way to do this?

Thanks,
Nate

13 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 23 Feb 2009, 08:48 AM
Hello nbahl,

First I want to apology for the late answer.
You can set the culture property of RadDatePicker and customize the Culture ShortDatePattern property in order to change the date format.
Here is a snippet changing the display date to MM/yyyy.

CultureInfo cultureInfo = new CultureInfo("en-US");  
DateTimeFormatInfo dateInfo = new DateTimeFormatInfo();  
dateInfo.ShortDatePattern = "MM/yyyy";  
cultureInfo.DateTimeFormat = dateInfo;  
radDatePicker1.Culture = cultureInfo; 

Let me know if you need more information.

Sincerely yours,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
nbahl
Top achievements
Rank 1
answered on 23 Feb 2009, 07:02 PM
Worked perfectly....thank you.
0
nbahl
Top achievements
Rank 1
answered on 28 Apr 2009, 02:24 PM
Hristo,

I have run into a problem when using this code.  If I pick a date from the calendar it works perfectly, but if I type in a date I get an error "Object reference not set to an instance of an object".  Below is the stack trace if that helps.  I am on Q1 2009 release.  Also is there a way to create a shortcut for entering the current date? Ex. if a user enters "/" it defaults in todays date.

Thanks!
Nate Bahl


   at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEvaluator.GetFirstAvailablePosition(Token token, Dictionary`2 inputBuckets)
   at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEvaluator.Distribute(Token[] originalTokens)
   at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEvaluator.GetDate(Token[] tokens, DateTime date)
   at Telerik.Windows.Controls.DatePicker.DateTimeParsing.TripletEntry.Evaluate(DateTime currentDate, FormatInfo formatInfo)
   at Telerik.Windows.Controls.DatePicker.DateTimeParsing.DateTimeEntry.Evaluate(DateTime currentDate, FormatInfo formatInfo)
   at Telerik.Windows.Controls.RadDatePicker.ParseDateAndUpdateTextBox()
   at Telerik.Windows.Controls.RadDatePicker.OnInputBoxLostFocus(Object sender, RoutedEventArgs e)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.OnLostFocus(RoutedEventArgs e)
   at System.Windows.Controls.Primitives.TextBoxBase.OnLostFocus(RoutedEventArgs e)
   at System.Windows.UIElement.IsFocused_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.Controls.TextBox.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.ClearValueCommon(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata)
   at System.Windows.DependencyObject.ClearValue(DependencyPropertyKey key)
   at System.Windows.Input.FocusManager.OnFocusedElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at System.Windows.Input.FocusManager.SetFocusedElement(DependencyObject element, IInputElement value)
   at System.Windows.Input.KeyboardNavigation.UpdateFocusedElement(DependencyObject focusTarget)
   at System.Windows.FrameworkElement.OnGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
   at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew)
   at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
   at System.Windows.UIElement.Focus()
   at System.Windows.Input.KeyboardNavigation.Navigate(DependencyObject currentElement, TraversalRequest request, ModifierKeys modifierKeys, DependencyObject firstElement)
   at System.Windows.Input.KeyboardNavigation.Navigate(DependencyObject sourceElement, Key key, ModifierKeys modifiers)
   at System.Windows.Input.KeyboardNavigation.ProcessInput(InputEventArgs inputEventArgs)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at System.Windows.Forms.Integration.ElementHost.ProcessCmdKey(Message& msg, Keys keyData)
   at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
   at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at WinFormTestControl.Program.Main() in C:\rccdev\utilnxt\net\BankReconcilation\WinFormTestControl\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
0
Miroslav
Telerik team
answered on 01 May 2009, 09:04 AM
Hello Nate,

It seems that there is a bug in the DateTime parser. It expects the day component of the date to always be there. We have logged this as an issue and it will be fixing it for the next SP or Q2 release.

Your Telerik points have been updated for the bug report.

As for your second question: you can register for the KeyDown event and change the date there, like so:

    datePicker.KeyDown += new KeyEventHandler(datePicker_KeyDown);  
 
void datePicker_KeyDown(object sender, KeyEventArgs e)  
{  
    if (e.Key == Key.Subtract)  
    {  
        var datePicker = sender as RadDatePicker;  
        datePicker.SelectedDate = DateTime.Now;  
        e.Handled = true;  
    }  


All the best,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
James
Top achievements
Rank 1
answered on 12 Jul 2009, 06:18 AM
Is there any way to set the display date format using only XAML?
0
Boyan
Telerik team
answered on 14 Jul 2009, 11:21 AM
Hi James,

 For now there is no way to set the format in XAML. You have to set it in code.

All the best,
Boyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
matt
Top achievements
Rank 1
answered on 27 Jul 2009, 06:15 AM
The date picker parser problem mentioned above (null ref exception when using a date format without days) still exists in the q2 release.
0
Boyan
Telerik team
answered on 28 Jul 2009, 03:39 PM
Hi matt,

Yes, this is not fixed. We are reworking RadCalendar and RadDatepicker for Q3. We are making major structure changes of this two controls as  current implementation is not good enough and SL3 was released which gives the opportunity for some improvements. That's why we have frozen all fixes for the current implementation.
 Sorry for the inconvenience caused. You can expect improved version of this controls for Q3.

Regards,
Boyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
matt
Top achievements
Rank 1
answered on 29 Jul 2009, 09:38 AM
If the controls are being reworked a simple way to make the date picker a month picker or a year picker would be good. I.e. Select a month and have that set the selected date to the first day of the month instead of drilling down into the day view. I have this working with the current control but it was not straight forward. It required a month template with a button and the click event can be handled etc. Even a click event on CalendarButton would be good and a way to cancel the default behaviour of drilling down to the day view. With a display format on the text box of MMM yyyy it would make a simple month picker. Currently we have to live with what feels like a hacky solution and a date format that includes the days. A way to disable the parser altogether would be good and I am guessing stop problems like the one in this thread if it is not required.
0
Henrique Duarte
Top achievements
Rank 1
Veteran
answered on 29 Jul 2009, 10:30 AM
Hello matt,

I'm waiting for this implementation too.
I opened a support ticket for that with a sample code:

private void RadDatePicker_DisplayModeChanging(object sender, CalendarModeChangedEventArgs e)     
{     
    if (e.NewMode == DisplayMode.MonthView)     
    {     
        e.Cancel = true;     
        ((RadDatePicker)e.Source).SelectedDate = ((RadDatePicker)e.Source).Calendar.CurrentDate;     
    }     

The are two problems:
1 - They don't have *YET* a "DisplayModeChanging" method, only "DisplayModeChanged";
2 - The Calendar is private, so we cannot access the CurrentDate.

If we have luck, maybe this implementation will be on next build.

Best regards,

Henrique
0
Kaloyan
Telerik team
answered on 30 Jul 2009, 02:10 PM
Hi Henrique Duarte,

We appreciate you suggestion and will consider such features for the Q3 2009 release. Thanks once again.


Sincerely yours,
Kaloyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Suman
Top achievements
Rank 1
answered on 06 Jan 2014, 02:36 PM
Hi,

I have added your code snippet, but could not resolve. Can you send more details xaml and code.
EG,

CultureInfo cultureInfo = 
new CultureInfo("en-US");  
DateTimeFormatInfo dateInfo = new DateTimeFormatInfo();  
dateInfo.ShortDatePattern = "MM/yyyy";  
cultureInfo.DateTimeFormat = dateInfo;  
radDatePicker1.Culture = cultureInfo; 


Thanks
Suman
0
Yana
Telerik team
answered on 08 Jan 2014, 09:21 AM
Hi Suman,

Please check the following article which demonstrates how to set a custom date format to the RadDateTimePicker control:
http://www.telerik.com/help/wpf/raddatetimepicker-features-formatting.html

I hope this helps.

Regards,
Yana
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DatePicker
Asked by
nbahl
Top achievements
Rank 1
Answers by
Hristo
Telerik team
nbahl
Top achievements
Rank 1
Miroslav
Telerik team
James
Top achievements
Rank 1
Boyan
Telerik team
matt
Top achievements
Rank 1
Henrique Duarte
Top achievements
Rank 1
Veteran
Kaloyan
Telerik team
Suman
Top achievements
Rank 1
Yana
Telerik team
Share this question
or