1

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

  1. 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
  2. QUARTERLY- 3 months. if the user will input START DATE : 10/2016 the end should be END DATE : 10/2016 valid

  3. SEMI ANNUAL - 6 MONTHS if the user will input START DATE : 10/2016 the end should be END DATE : 03/2016 valid

  4. ANNUAL - 12 MONTHS if the user will input START DATE : 01/2016 the end should be END DATE : 12/2016 valid

  5. 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
Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
Mikelemuel
  • 378
  • 1
  • 3
  • 15

1 Answers1

1
                    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
Mikelemuel
  • 378
  • 1
  • 3
  • 15