Carl R
Carl R

Reputation: 11

If datetimepicker value greater than end datetimepicker value then

I am trying to write an if statement for two datetimepickers. I have a start date and end date and I do not want the value of the start date to be greater than the end date.

Here is what I have tried but doesn't work:

If dateStart.Value.Date < dateend.Value.Date Then

    lblstatus.Text = "Status: Start date must be a date before end date."

Else

End If

Upvotes: 0

Views: 2095

Answers (3)

MattE
MattE

Reputation: 1114

lblstatus.Text = dateStart.Value.Date > dateEnd.Value.Date ? "Status: Start date must be a date before end date." : dateStart.Value.Date(Or whatever you want to happen if it is a valid date by your condition check)

Upvotes: 0

Slai
Slai

Reputation: 22876

as alternative you can change the .MinDate and .MaxDate properties in the ValueChanged event

Sub init()
    AddHandler dateStart.ValueChanged, Sub() dateEnd.MinValue = dateStart.Value
    AddHandler dateEnd.ValueChanged, Sub() dateStart.MaxValue = dateEnd.Value
End Sub

Upvotes: 0

kiLLua
kiLLua

Reputation: 471

Your Operator is wrong .. it should be greater than, not less than :)

    If dateStart.Value.Date > dateend.Value.Date Then

        lblstatus.Text = "Status: Start date must be a date before end date."

    Else

Upvotes: 2

Related Questions