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!

Separate dates by month/quarters

Status
Not open for further replies.

seashore67

Technical User
May 27, 2003
51
US
I am attempting to do a query on a date field in order to separate everything by quarters. I want to be able to separate them into quarters (i.e. jan-mar, apr -jun, etc...) no matter what the year is. The date field includes the year and is causing me troubles. Any help in this matter is appreciated.

Thank you,
Andrew
 
The DatePart function will return a quarter for any DateTime field with
[tt]
DatePart ( "q", [DateTimeField] )
[/tt]
 
Golom,

I'm assuming I put this in the criteria section. When I run the query it then asks me for a parameter value for that function. I'm a novice so I might not have understood you correctly.

Thanks again,
Andrew
 
There are several places you might put it depending on the result that you want. For example
[tt]
Select Field1, Field2,
DatePart ( "q", [DateTimeField] ) As [Quarter]

From tbl

Where DatePart ( "q", [DateTimeField] ) = 2
[/tt]

Creates a field named "Quarter" using the datepart function and Where DatePart ( "q", [DateTimeField] ) = 2 limits the returned records to those where its the second quarter OR
[tt]
Select DatePart ( "q", [DateTimeField] ) As [Quarter],
SUM(Field1) As FieldTotal

From tbl

Group By DatePart ( "q", [DateTimeField] )
[/tt]

Computes the sum of all "Field1" values for each quarter.

Switch to SQL view and copy and paste your SQL and we may be able to give more specific advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top