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
- END DATE : 10/2018
How can I validate Quarterly
- START DATE : 01/2018
- END DATE : 03/2018.
- Quarterly are (Jan to Mar, Apr to Jun, July to Sep, Oct to Dec)
How can I validate Semi-annual
- START DATE : 01/2018
- END DATE : 06/2018
- SEMI - ANNUAL ARE ( JAN TO JUN, JULY TO DECEMBER)
How can I validate Annual
- START DATE: 01/2018
- END DATE: 12/2018
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)
- example START DATE : 10/2016 end date should be END DATE : 10/2016. valid
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