Solved

How to calculate the date range of the current and next quarter date

Posted on 2006-07-19
3
506 Views
Last Modified: 2008-03-06
Is there any easy way to get the begin date and end of the current quarter in VB.net?  I also need to get the date range for the next quarter?  This is all based on the current date.

Thanks in advance,
Brian Pembroke
0
Comment
Question by:u7c76
3 Comments
 
LVL 5

Accepted Solution

by:
nickhoggard earned 500 total points
ID: 17140974
Hi,

The following article discusses some functions for dealing with the quarters:
http://www.codeproject.com/csharp/csdatetimelibrary.asp?df=100&forumid=157955&exp=0&select=1055875

Keep in mind though that if your application is being designed for multiple countries that the quarters are different in different locations (eg here in New Zealand the first quarter runs from 1 April to 30 June)

Hope this gets you started.

Cheers

Nick
0
 
LVL 9

Expert Comment

by:dancebert
ID: 17141001
Actually, quarters vary by company as well as by country.  Any solution that calculates financial quarters must either specify or assume what is the first day of the fiscal year.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17141380
Here are two functions that I use:

  ''' -----------------------------------------------------------------------------
  ''' <summary>
  ''' Overloaded version, assuming U.S. settings
  ''' </summary>
  ''' -----------------------------------------------------------------------------
  Public Shared Sub GetQuarter(ByVal dateSelected As Date, _
   ByRef startDate As Date, ByRef endDate As String)

    GetQuarter(dateSelected, FirstDayOfWeek.Monday, FirstWeekOfYear.Jan1, startDate, endDate)

  End Sub

  ''' -----------------------------------------------------------------------------
  ''' <summary>
  ''' Get the first and last date of the quarter for a given date.
  ''' </summary>
  ''' <param name="dateSelected">Selected date</param>
  ''' <param name="firstWeekDay">Enum for the first day of the week</param>
  ''' <param name="firstYearWeek">Enum for the first week of the year</param>
  ''' <param name="startDate">Return the start date for the quarter</param>
  ''' <param name="endDate">Return the end date for the quarter</param>
  ''' -----------------------------------------------------------------------------
  Public Shared Sub GetQuarter(ByVal dateSelected As Date, _
   ByVal firstWeekDay As FirstDayOfWeek, ByVal firstYearWeek As FirstWeekOfYear, _
   ByRef startDate As Date, ByRef endDate As String)

    Dim quarter As Integer = DatePart(DateInterval.Quarter, dateSelected)

    startDate = New DateTime(dateSelected.Year, ((quarter - 1) * 3) + 1, 1)

    endDate = DateAdd(DateInterval.Quarter, DatePart(DateInterval.Quarter, dateSelected, firstWeekDay, firstYearWeek), _
       New DateTime(dateSelected.Year, 1, 1)).AddDays(-1)

  End Sub

Bob
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net - Get ColumnNames of SQL Table 4 15
.NET 2008 VB and C# 6 39
Help with adding DLL file in Windows project 20 40
Get month and date in a format 4 31
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question