Mikelemuel
Mikelemuel

Reputation: 378

ASP.NET : How to accept Monthly, Quarterly, Semi-Annual, Anually of Period of time using Dropdown using visual basic

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:

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

Upvotes: 1

Views: 348

Answers (1)

Mikelemuel
Mikelemuel

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

Related Questions