how to determine quarter of year, on the basis of

# Thread: how to determine quarter of year, on the basis of

1. Senior Member
Join Date
Dec 1969
Posts
114

## how to determine quarter of year, on the basis of

Hi all,<BR><BR>In my application I am trying to fill in a field with the quarter of the year and year itself .. on the basis of input date that would be in mm/dd/yyyy format . The calculation needs to be done on the sql server (probably in a sp) as the final result would be parsed to a crystal report from that sp. Any suggestions are highly appreciated <BR><BR>Thanks in Advance!

2. Senior Member
Join Date
Dec 1969
Posts
1,849

## If structures

dtm_month = month(date)<BR>if dtm_month &#062;=1 and dtm_month &#060;= 3 then<BR> quarter = 1<BR>elseif dtm_month &#062;=4 and dtm_month &#060;= 6 then<BR> quarter = 2<BR>elseif dtm_month &#062;=7 and dtm_month &#060;=9 then<BR> quarter = 3<BR>elseif dtm_month &#062;=10 and dtm_month &#060;=12 then<BR> quarter = 4<BR>end if<BR><BR><BR>Thats basing the first quarter starting in January.

3. Senior Member
Join Date
Dec 1969
Posts
11,334

## Or right in sql

DATEPART ( datepart , date ) <BR><BR>and use &#039;qq&#039; or &#039;q&#039; as the datepart variable.<BR><BR>Either way.....

4. Senior Member
Join Date
Dec 1969
Posts
114

## RE: Or right in sql

its implemented in a view rather than sp so cant pass date to it, will probably have to do something like Wholsea mentioned incrystal formulas for the smallest date i am getting back from the view<BR><BR>Thanks

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## HUH?

DATEPART( qq, MIN(dateField) )<BR><BR>???<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•