Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Quarter Dates

Explorer ,
Feb 20, 2007 Feb 20, 2007
How do I get previous and next quarter dates in coldfusion?
______________________________________________

Using the below function I will get current quarter.
<cfoutput>#Quarter(Now())#</cfoutput>. ---> Output ---> Q1
Q#Quarter(Now())#-#DateFormat(Now(), "yyyy")# --> Output ----> Q1-2007

I want the previous and next quarter dates in below format. (Considering the date as today's date ie. 21st Feb 2007)
Q4-2006 from (October 1st to December 31st).
Q2-2007 from (April 1st to June 30th).

Can anyone help me.

Thanks & Regards,
Satheesh.
970
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 20, 2007 Feb 20, 2007
Did you check out the DateAdd function?

- Mike
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 20, 2007 Feb 20, 2007
We do stuff like that by having a table called period. The primary key is date. Other fields are fiscal year, fiscal period, holiday, etc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 20, 2007 Feb 20, 2007
Thanks guys for your reply.

I have done it through sql query:

The below query will give me out of previous quarter with year.
If Getdate() - 2007-02-21 15:29:22.850
I require previous quater. Hence I used the below logic in SQL Server.

SELECT
CASE WHEN MONTH(GETDATE()) IN ( 1, 2, 3) THEN 'Quarter 4, ' + CAST(YEAR(GETDATE())-1 AS VARCHAR(4))
WHEN MONTH(GETDATE()) IN ( 4, 5, 6) THEN 'Quarter 1, ' + CAST(YEAR(GETDATE())-1 AS VARCHAR(4))
WHEN MONTH(GETDATE()) IN ( 7, 8, 9) THEN 'Quarter 2, ' + CAST(YEAR(GETDATE())-1 AS VARCHAR(4))
WHEN MONTH(GETDATE()) IN (10, 11, 12) THEN 'Quarter 3, ' + CAST(YEAR(GETDATE())-1 AS VARCHAR(4))
END as PreQuarter
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 21, 2007 Feb 21, 2007
LATEST
I'm not sure if it really makes a difference, but the following code might be a little faster:

select 'PreQuarter' = case when month(GETDATE()) <= 3 then 'Quarter 4'
when month(GETDATE()) <= 6 then 'Quarter 1'
when month(GETDATE()) <= 9 then 'Quarter 2'
when month(GETDATE()) <= 12 then 'Quarter 3' end,
'PreYear' = Year(GETDATE())-1
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources