I have the vb net code for first and last day of the Quarter, but I am trying to do this for first and last day of Bi monthly period ( which end on these months Feb, Apr, Jun, Aug, Oct, Dec)
So the bimonthly start and end dates are Jan 1 to Feb 28 (or 29) Mar 1 to Apr 30, May 1 to Jun 30, etc
Any ideas how to do this? (in Vb thanks)
'To get the first day of the quarter
Public Shared Function xFirstDayOfQuarter(ByVal theDay As DateTime) As DateTime
Dim currQuarter As Integer = (Month(theDay) - 1) \ 3 + 1
Dim FirstDayQuarter As DateTime = DateSerial(Year(theDay), 3 * currQuarter - 2, 1)
Return FirstDayQuarter
End Function
'To get the last day of the quarter
Public Shared Function xLastDayOfQuarter(ByVal theDay As DateTime) As DateTime
Dim currQuarter As Integer = (Month(theDay) - 1) \ 3 + 1
Dim LastDayQuarter As DateTime = DateSerial(Year(theDay), 3 * currQuarter + 1, 0)
Return LastDayQuarter
End Function
This how far I got ..
Private Function DayOfBiMonth(ByVal theDay As DateTime, ByVal FirstOrLast As Integer) As DateTime
Dim res As DateTime = Util.gBASEDATE
Dim Mth As Integer = Month(theDay)
Dim Yr As Integer = Year(theDay)
Dim BiMonth As Integer = -1
Select Case Mth
Case Is = 1, 2
If FirstOrLast = 1 Then
BiMonth = 1
ElseIf FirstOrLast = 2 Then
BiMonth = 2
End If
Case Is = 3, 4
If FirstOrLast = 1 Then
BiMonth = 3
ElseIf FirstOrLast = 2 Then
BiMonth = 4
End If
Case Is = 5, 6
If FirstOrLast = 1 Then
BiMonth = 5
ElseIf FirstOrLast = 2 Then
BiMonth = 6
End If
Case Is = 7, 8
If FirstOrLast = 1 Then
BiMonth = 7
ElseIf FirstOrLast = 2 Then
BiMonth = 8
End If
Case Is = 9, 10
If FirstOrLast = 1 Then
BiMonth = 9
ElseIf FirstOrLast = 2 Then
BiMonth = 10
End If
Case Is = 11, 12
If FirstOrLast = 1 Then
BiMonth = 11
ElseIf FirstOrLast = 2 Then
BiMonth = 12
End If
End Select
If FirstOrLast = 1 Then
res = DateSerial(Yr, BiMonth, 1)
ElseIf FirstOrLast = 2 Then
res = DateSerial(Yr, BiMonth, 20)
res = Util.LastDayOfMonth(res)
End If
Return res
End Function
Private Function LastDayOfMonth(ByVal theDay As DateTime) As DateTime
Dim FirstDayMonth As DateTime = DateSerial(Year(theDay), Month(theDay), 1)
Dim LastDayMonth As DateTime = FirstDayMonth.AddMonths(1).AddDays(-1)
Return LastDayMonth
End Function
20
in the DateSerial call? (Not that it matters, yourLastDayOfMonth
throws it away anyway) – Ben Voigt