0

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
1
  • 1
    You are showing the error message if the start date is less than the end date. It looks like you need to use >= instead of < in the comparison. Commented Aug 15, 2016 at 23:41

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0
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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.