sfDateTimeEdit does not return a valid date

When trying to convert sfDateTimeEdit.Value into a formatted string, you will need to first convert the value into a date, otherwise a runtime error will occur (Converting a string to an integer).


This code will cause the error:

g.DrawString(e(sdt_ACCTRPT_StartDate.Value).ToString("MMM d, yyyy"), fGarmond_11, Brushes.Black, 625, y)


where as, this fixes it:

g.DrawString(CDate(sdt_ACCTRPT_StartDate.Value).ToString("MMM d, yyyy"), fGarmond_11, Brushes.Black, 625, y)


1 Reply

KS Koppolu Sai Sivani Koppolu Ragaiah Syncfusion Team July 31, 2025 12:21 PM UTC

Hi Gary Smith,

 
The Value property in SfDateTimeEdit represents a nullable DateTime. Directly invoking .ToString("MMM d, yyyy") on it causes VB.NET to interpret it as an Object, potentially resulting in an InvalidCastException during runtime. To resolve this, we’ve implemented null handling using the If operator to ensure a valid DateTime before formatting.

Please refer the attached sample and let us know if you have any questions or need further assistance.

Regards,
K Sai Sivani


Attachment: SfDateTimeEdit_TypeCast_3b7aded7.zip

Loader.
Up arrow icon