Reputation: 3
The answer to this is most likely all over the web, and I just can't find it.
I'm writing a C# Web Form, and need to obtain the return value of the calender so that I can convert it to a string (if that is at all possible), however, I have no idea what the return value of it is.
For example: to get the "return value" of a dateTimePicker
to turn into a string in C# Windows Forms, you simply input dateTimePicker1.Value.ToShortDateString();
, however, this should be easier, and yet I can't figure it out.
Thanks for any input in advance!
Upvotes: 0
Views: 680
Reputation: 1782
This is very straightforward:
Calendar1.SelectedDate.ToLongDateString();
Adding a reference for posterity: http://msdn.microsoft.com/en-US/library/system.web.ui.webcontrols.calendar.selecteddate(v=vs.100)
Use the SelectedDate property to determine the selected date on the Calendar control.
The SelectedDate property and the SelectedDates collection are closely related. When the SelectionMode property is set to CalendarSelectionMode.Day, a mode that allows only a single date selection, SelectedDate and SelectedDates[0] have the same value and SelectedDates.Count equals 1. When the SelectionMode property is set to CalendarSelectionMode.DayWeek or CalendarSelectionMode.DayWeekMonth, modes that allows multiple date selections, SelectedDate and SelectedDates[0] have the same value.
The SelectedDate property is set using a System.DateTime object.
When the user selects a date on the Calendar control, the SelectionChanged event is raised. The SelectedDate property is updated to the selected date. The SelectedDates collection is also updated to contain just this date.
Upvotes: 2
Reputation: 23796
Assuming you are using the out of the box calendar control:
Calendar1.SelectedDate.ToShortDateString()
Upvotes: 2
Reputation: 3597
You need to cast:
DateTime dt = (DateTime)dateTimePicker1.value;
string dtString = dt.ToShortDateString();
Upvotes: 0