Marvin Retro
Marvin Retro

Reputation: 35

If datetimepicker1 is greater than datetimpicker2

I would like to ask a question :( I'm already confuse since i want to show a message box that contains "Invalid Date" if datetimepicker1 is greater than datetimepicker2

Thank you for those who will help :)

Upvotes: 1

Views: 183

Answers (3)

IbraHim M. Nada
IbraHim M. Nada

Reputation: 660

you Can set the value of datetimepicker1.MinimumDateTime(datetimepicker2.Value) or you can Compare the tow values with each other hope that helps :)

Update its the same as the answer i just needed to modify my answer to make it better and generic

 DateTime dateOne ;
  dateOne = dateTimePicker1.Value;
DateTime dateTow ;
  dateTow = dateTimePicker2.Value;
if (dateOne > dateTow  ) {console.writeline("Date Number One is Bigger")}

else{console.writeline("Date Number tow is Bigger");}

Upvotes: 0

anis programmer
anis programmer

Reputation: 999

You can check this way:

DateTime iDate;
      iDate = dateTimePicker1.Value;
    DateTime eDate;
      eDate = dateTimePicker2.Value;
    if (iDate > eDate ) {
      MessageBox.Show("Invalid Date.");
    }

Upvotes: 1

Jeremy Thompson
Jeremy Thompson

Reputation: 65544

if (dateTimePicker1.Value > dateTimePicker2.Value ) {
  MessageBox.Show("Invalid Date.");
}

Upvotes: 1

Related Questions