System.FormatException throwing from DateTimeEdit

Hello!

I am using the DateTimeEdit control, version 29.1.41.

This error occurs on some of our customers' PCs:

System.FormatException: String '2025-05-22(목) 오전 12:00:00' was not recognized as a valid DateTime.

   at System.DateTime.Parse(String s, IFormatProvider provider)

   at Syncfusion.Windows.Shared.DateTimeEdit.CoerceDateTime(DependencyObject d, Object baseValue)

   at Syncfusion.Windows.Shared.DateTimeEdit.DateTimeEdit_Loaded(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.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)

   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)

   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()

   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()

   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)

   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)

   at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)

   at System.Windows.Interop.HwndTarget.OnResize()

   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)

   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)

   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)


It seems the DateTime is being converted to a localized string, and the format cannot be recognized.
However, in our code, we are not using any string conversion.
The value is correctly bound as a DateTime.

WPF code

<shared:DateTimeEdit Width="120" Margin="0,0,5,0" DateTime="{Binding StartDate}" />


ViewModel Code:

private DateTime _startDate;

public DateTime StartDate

{

    get => _startDate;

    set => this.RaiseAndSetIfChanged(ref _startDate, value);

}

It appears that the ToString() method is being used internally within DateTimeEdit, causing the issue.

We would appreciate a prompt fix for this error.

Thank you.



Edit: I believe this part may be the cause of the issue.
In the CoerceDateTime method:

        DateTime? dateTime2;

        if (dateTimeEdit.TemplatedParent == null)

        {

            Syncfusion.Windows.Controls.Calendar calendar = dateTimeEdit.GetCalendar();

            if (calendar != null && calendar.BlackoutDates != null && string.IsNullOrEmpty(dateTimeEdit.DateTime.ToString()) && !string.IsNullOrEmpty(System.DateTime.Today.ToString()) && calendar.BlackoutDates.Contains(System.DateTime.Today))

            {

                return (DateTime?)null;

            }


            dateTime2 = System.DateTime.Parse(System.DateTime.Today.ToString((d as DateTimeEdit).CultureInfo), (d as DateTimeEdit).CultureInfo);

            if (dateTime2 > dateTimeEdit.MaxDateTime)

            {

                dateTime2 = dateTimeEdit.MaxDateTime;

            }


            if (dateTime2 < dateTimeEdit.MinDateTime)

            {

                dateTime2 = dateTimeEdit.MinDateTime;

            }

        }

        else

        {

            dateTime2 = null;

        }


Why is it necessary to convert today's date to a localized string format and then parse it back into a DateTime?


Edit2 :  I checked the region and date settings on the customer's PC. They are slightly different from the default settings.

datetimeformat.jpg

TMI: Due to the 100KB size limit for attachments, I had to reduce the image quality.
Please consider increasing the file size limit.


I encountered a similar issue a long time ago, so I used code like this to work around it:

CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();

culture.DateTimeFormat.LongDatePattern = "yyyy-MM-dd";

culture.DateTimeFormat.LongTimePattern = "HH:mm:ss";

culture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";

culture.DateTimeFormat.ShortTimePattern = "HH:mm:ss";

System.Threading.Thread.CurrentThread.CurrentCulture = culture;

System.Threading.Thread.CurrentThread.CurrentUICulture = culture;


This code does resolve the issue, but it causes inconvenience for the customer.
Other third-party software works fine even with custom regional settings.

Please help resolve this issue.


1 Reply

BS Bhaskar Suresh Syncfusion Team May 26, 2025 12:50 PM UTC

Hi Seung-Joo Cha,


We are unable to reproduce the reported issue based on the given information. Please refer to the sample for your reference.

Could you please share the following information so that we can better analyze the issue and provide a solution?

  • Code snippet of the control.
  • Modified sample that replicates the issue.

The maximum file size allowed is 30MB. Therefore, please compress all the required files into a single folder and share it accordingly.


Regards,

Bhaskar Suresh


Attachment: DateTimeEdit_Format_9b81da36.zip

Loader.
Up arrow icon