I got a file which has dates stored as the following format (yyyy|dMM|dd). I now need to retrieve the values from this file and set the datetimepicker to the correct year month and day matching the ones in the stored string. Im able to retrieve all data correctly only i dont know how to set the calander correctly matching the strings. This is what i got so far although it doesnt work:
string[] editdate = clean[3].Split('|');
EditDatepickCalendar.Value = DateTime.Parse("{0},{1},{2}", editdate[0], editdate[1], editdate[2]);
If sounds like you should just be using DateTime.ParseExact:
DateTime date = DateTime.ParseExact(clean[3], "yyyy'|'MM'|'dd",
CultureInfo.InvariantCulture);
Quoting the | isn't strictly necessary here, but it makes it clear that you're just intending them to be taken as literal text, rather than having any date/time-related meaning.
(Note that the problem really isn't anything to do with the DateTimePicker here - it's parsing the value. When you run into an issue, you should perform appropriate diagnostics to work out where it is - in the UI, data tranformation, storage etc.)
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