1

Can anyone help me on how can I validate given DateTime between two DateTime using vb.net?

the given DateTime must not in between the two DateTime..

3 Answers 3

4

You can compare date instances the same way you would compare numbers as they override the LessThan, LessThanOrEqual, GreaterThan and GreaterThanOrEqual operators:

Dim minDate = New DateTime(2009, 4, 17) Dim maxDate = New DateTime(2011, 4, 17) Dim selectedDate = New DateTime(2010, 4, 17) If selectedDate > minDate And selectedDate < maxDate Then Console.WriteLine("selected date is valid") Else Console.WriteLine("selected date is invalid") End If 
Sign up to request clarification or add additional context in comments.

Comments

1

Use DateTime.Compare

Dim date1 As New DateTime(100) Dim date2 As New DateTime(200) Dim workingDate As New DateTime(150) If DateTime.Compare(workingDate , date1) >= 0 AND DateTime.Compare(workingDate , date2) <= 0 Then Console.WriteLine("Between") Else Console.WriteLine("Not Between") End If 

Comments

0
Dim dt As Date = DateTimePicker1.Value.Date If dt < CDate("2010-04-01") Or dt > CDate("2010-04-10") Then MessageBox.Show("Date is not in the first 10 days of April so is ok") End If 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.