I have created a function that I feed a quarter (1, 2, 3 or 4) and a year (for example 2014). This function then calculates the first and the last day of this quarter.
It works fine sometimes, but when I feed quarter "4", I get an argument-out-of-range-exception in this line:
Dim dtLastDay As New DateTime(uYear, 3 * uQuarter + 1, 1)
I am not sure why this happens. Can somebody help?
Thank you very much!
Public Sub QuarterYearToDates(ByVal uQuarter As Integer, ByVal uYear As Integer, ByRef uStart As Date, ByRef uEnd As Date)
Dim iMonth As Integer
If uQuarter = 1 Then
iMonth = 1
ElseIf uQuarter = 2 Then
iMonth = 4
ElseIf uQuarter = 3 Then
iMonth = 7
ElseIf uQuarter = 4 Then
iMonth = 10
End If
Dim dtFirstDay As New DateTime(uYear, 3 * uQuarter - 2, 1)
Dim dtLastDay As New DateTime(uYear, 3 * uQuarter + 1, 1)
dtLastDay = dtLastDay.AddDays(-1)
uStart = dtFirstDay
uEnd = dtlastday
End Sub