Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to get date from calendar.SelectedDate in format dd/MM/yyyy [closed]

I need to get selected date from calendar and show it in textbox in format dd/MM/yyyy. I have this code, but it does not work.

datum_odevzdani.Text = (calendar_odevzdani.SelectedDate.ToString("dd/MM/yyyy"));
like image 971
FrankieCC Avatar asked Oct 29 '25 05:10

FrankieCC


1 Answers

The type of the Calendar.SelectedDate property is Nullable<DateTime>. Hence you have to access the contained DateTime by the Nullable<T>.Value property:

if (calendar_odevzdani.SelectedDate.HasValue)
{
    datum_odevzdani.Text = calendar_odevzdani.SelectedDate.Value.ToString("dd/MM/yyyy");
}
like image 101
Clemens Avatar answered Oct 30 '25 22:10

Clemens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!