Reputation: 378
Scenario. I have a dropdown list of Month(1-12) and Year (MMYYYY) format.
Start Date : Month(1-12) and Year (MMYYYY) format
End Date : Month(1-12) and Year (MMYYYY) format
If I would select the START DATE : 10/2018 (then the start date is valid) start date should not be more than 5 years based on the current year Then the "END DATE" should be End DATE : 10/2018 ( this is valid) End date should not be more than 5 years from the start date.
Question:
How can I validate MonthSTART DATE : 10/2018
How can I validate Quarterly
How can I validate Semi-annual
How can I validate Annual
The above question will match my explanation below
Monthly - whenever the user choose the start date (should not be more than 5 years from the current date)
QUARTERLY- 3 months. if the user will input START DATE : 10/2016 the end should be END DATE : 10/2016 valid
SEMI ANNUAL - 6 MONTHS if the user will input START DATE : 10/2016 the end should be END DATE : 03/2016 valid
ANNUAL - 12 MONTHS if the user will input START DATE : 01/2016 the end should be END DATE : 12/2016 valid
else INVALID
Output: valid or invalid
Kindly see the code below
Dim dateStart As Date=New Date(ddl_dateStartYear.SelectedValue,ddl_dateStartMonth.SelectedValue, 1)
Dim dateEnd As Date = New Date(ddl_dateEndYear.SelectedValue, ddl_dateEndMonth.SelectedValue, 1)
' Today check
If dateEnd > DateTime.Now.AddYears(5) Then
' Invalid
End If
' Five year check
If dateStart.AddYears(5) > dateEnd Then
' Invalid
End If
Upvotes: 1
Views: 348
Reputation: 378
If dateStart = dateEnd Then
'valid
ElseIf dateStart.AddMonths(3) = dateEnd Then
'valid
ElseIf dateStart.AddMonths(6) = dateEnd Then
'valid
ElseIf dateStart.AddMonths(12) = dateEnd Then
'valid
Else
MsgBox("Please choose that would match to Monthly, Quarterly, Semi-Annual, Annual Payments!")
End If
Upvotes: 1