Cursed
Cursed

Reputation: 1003

Converting custom DateTimepicker value to datetime

I have a List where i want to find all the rows where a date is equal to dataTimePicker the problem is that dataTimePicker.value gives DateTime which is what i need but in a wrong format like 8/26/2019 and if i parse it from string to DateTime it returns me that the string is wrong.

I tried parse it to DateTime and convert to date nothing worked

DateTime da = DateTime.ParseExact(dateTimePicker1.Text, "dd-MM-yyyy", null);

I expect it to return a format like that ddMMyyyy

Upvotes: 0

Views: 463

Answers (1)

Edney Holder
Edney Holder

Reputation: 1228

The following should work for you.

This is just a sample class to use in the example

class MyClass
    {
        public DateTime ListDate;
        public String SomeData;
    }

Now the comparison becomes

foreach(MyClass myClass in myList)
{
     if(dateTimePicker1.Value.ToString("ddMMyyyy") ==  myClass.ListDate.ToString("ddMMyyyy"))
     {

     }
}

Upvotes: 1

Related Questions