Go Premium for a chance to win a PS4. Enter to Win

x
Solved

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

Posted on 2006-07-19
Medium Priority
512 Views
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.

Brian Pembroke
0
Question by:u7c76

LVL 5

Accepted Solution

nickhoggard earned 1500 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

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

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), _

End Sub

Bob
0

## Featured Post

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Screencast - Getting to Know the Pipeline
###### Suggested Courses
Course of the Month6 days, 23 hours left to enroll