Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

First Day of Quarter 1

Status
Not open for further replies.

pthalacker

Programmer
Aug 30, 2004
150
I am trying to get my head around the DatePart and DateAdd functions. I need to be able to determine the first day of the quarter from today's date.

Can you point me in the right direction?

pamela
 
first day of the quarter ?

Yes. Four quarters in a year. Standard accounting practice is quarterly reporting. One of the DateInterval enums is quarter. The quarters would be defined by the FirstDayofWeek and FirstWeekofYear values.

pamela
 
pthalacker,

Try something like this:
Code:
Public Function FirstDayOfQuarter(ByVal DateIn As DateTime) As DateTime
 Dim iQuarter As Integer = (DateIn.Month - 1) / 3 + 1
 Return DateSerial(DateIn.Year, 3 * iQuarter - 2, 1)
End Function

Public Function LastDayOfQuarter(ByVal DateIn As Date) As Date
   ' Calculate last day of DateIn quarter,
   ' with quarters ending at the end of Mar/Jun/Sep/Dec
   Dim iQuarterAs Integer = (Month(DateIn) - 1) \ 3 + 1
   Return DateSerial(Year(DateIn), 3 * iQuarter + 1, 0)
End Function

To use either of these functions, simply pass in the date for which you wish to retrieve the quarter, and it'll return the appropriate beginning/end date as a DateTime data type (an exact equivalent of the Date data type).

An example on how to use the functions is :
Code:
Dim QuarterStart As Date = FirstDayOfQuarter(Now)
Dim QuarterEnd As Date = LastDayOfQuarter(Now)

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT * FROM Users WHERE clue > 0
0 Rows Returned

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Thank you PsychoCoder. I found it a couple of days ago. I am using the Datepart() function to get the quarter however.

pamela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top