Selcuk SZR Selcuk SZR - 1 year ago 151
C# Question

DateTime.ParseExact Returns Wrong Value

I am trying to add hour and minute into the returning value of a datepicker(wpf). I think there is something wrong with my date format parameter for ParseExact(), but couldnt get where the problem is.

string[] timeAndDate = System.Text.RegularExpressions.Regex.Split(dPicker.SelectedDate.ToString(), " ");
string time = cmbTime.SelectedItem.ToString();
string tempDT = timeAndDate[0] + " " + time;
DateTime queryDT = DateTime.ParseExact(tempDT, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);

It keeps returning minValue 01.01.0001 etc. Its probably about these time dots. I also tried to add seconds but still no luck.

Btw tempDT is kinda "22.12.2016 20:30"

my input string is "22.12.2016 20:30"
method returns {01.01.0001 00:00:00}

I am also doing this to get two dates from datepickers and get two hour variables via two comboboxes, and make two datetime objects to send them to sql.

It seems I didnt put the debug point on the right place, embarrising but anyway, thanks so much!

Answer Source

Which values you are passing? I am using LinqPad here

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download