I know that Sql Server has some handy built-in quarterly stuff, but what about the .Net native DateTime object? What is the best way to add, subtract, and traverse quarters?
Is it a bad thing™ to use the VB-specific DateAdd() function? e.g.:
Dim nextQuarter As DateTime = DateAdd(DateInterval.Quarter, 1, DateTime.Now)
Edit: Expanding @bslorence's function:
Public Shared Function AddQuarters(ByVal originalDate As DateTime, ByVal quarters As Integer) As Datetime
Return originalDate.AddMonths(quarters * 3)
End Function
Expanding @Matt's function:
Public Shared Function GetQuarter(ByVal fromDate As DateTime) As Integer
Return ((fromDate.Month - 1) \ 3) + 1
End Function
Edit: here's a couple more functions that were handy:
Public Shared Function GetFirstDayOfQuarter(ByVal originalDate As DateTime) As DateTime
Return AddQuarters(New DateTime(originalDate.Year, 1, 1), GetQuarter(originalDate) - 1)
End Function
Public Shared Function GetLastDayOfQuarter(ByVal originalDate As DateTime) As DateTime
Return AddQuarters(New DateTime(originalDate.Year, 1, 1), GetQuarter(originalDate)).AddDays(-1)
End Function