title: How do I work with quarters (quarterly dates) in ASP.Net using VB.Net 2.0?
body: <p>I know that <a href="http://wiki.lessthandot.com/index.php/How_to_find_the_first_and_last_days_in_years,_months_etc" rel="nofollow noreferrer">Sql Server has some handy built-in quarterly</a> stuff, but what about the .Net native <a href="http://msdn.microsoft.com/en-us/library/system.datetime_members(VS.80).aspx" rel="nofollow noreferrer">DateTime</a> object? What is the best way to add, subtract, and traverse quarters?</p>
  
  <p>Is it a <em>bad thing</em>™ to use the VB-specific <a href="http://msdn.microsoft.com/en-us/library/hcxe65wz(VS.80).aspx" rel="nofollow noreferrer">DateAdd()</a> function? e.g.:</p>
  
  <pre><code>Dim nextQuarter As DateTime = DateAdd(DateInterval.Quarter, 1, DateTime.Now)
  </code></pre>
  
  <p>Edit: 
  Expanding @bslorence's function:</p>
  
  <pre><code>Public Shared Function AddQuarters(ByVal originalDate As DateTime, ByVal quarters As Integer) As Datetime
      Return originalDate.AddMonths(quarters * 3)
  End Function
  </code></pre>
  
  <p>Expanding @Matt's function:</p>
  
  <pre><code>Public Shared Function GetQuarter(ByVal fromDate As DateTime) As Integer
      Return ((fromDate.Month - 1) \ 3) + 1
  End Function
  </code></pre>
  
  <p>Edit: here's a couple more functions that were handy:</p>
  
  <pre><code>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
  </code></pre>