I currently have a program that takes the value from a datePicker and have the date saved as a string. I only needed the date not the time so i used the following code to save the date value:
DateTime StartDate;
String inMyString;
savedDate = datePicker1.SelectedDate.Value.Date;
inMyString = savedDate.Date.ToShortDateString()
I have the inMyString
pushedBack into my list and now i want to place it back into the datePicker.
On MSDN is shows me the following example to set the date.
dateTimePicker1.Value = new DateTime(2001, 10, 20);
the problem is that having .Value after my date picker is not an option (it doesn't show in Intellisense.)
I have also tried
datePicker1.SelectedDate.Value= new DateTime(inMyString)
and also converting the inMyString
to type DateTime
but it still does not work.
Any thoughts on how to do this?
Any Suggestions and comments are appreciated.
Thanks!
By default, the DatePicker value is null and the Calendar popup is hidden.
Answers. If you need to update the format of your Kendo UI datepicker, you should be able to use the setOptions function : datepicker. setOptions({ format: "MM/dd/yyyy });
By default DatePicker has standard height and width (height: '30px' and width: '143px'). You can change this height and width by using height and width property respectively.
Try this:
datePicker1.SelectedDate = new DateTime(2001, 10, 20);
If you need to take datetime from string:
datePicker1.SelectedDate = DateTime.Parse(inMyString);
Side note:
You can replace those 3 lines:
String inMyString;
savedDate = datePicker1.SelectedDate.Value.Date;
inMyString = savedDate.Date.ToShortDateString();
with one:
var inMyString = datePicker1.SelectedDate.Value.ToShortDateString();
Another side note: don't know if there is a reason to it, but you might consider storing datetime as dattime, not as a string.
If you want to show today's date in WPF C#, use this method:
datePicker1.SelectedDate = DateTime.Today.AddDays(-1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With