question

aman6496 avatar image
aman6496 asked

customized quarter calculation in sql

Hi Team, We have got a customized quarter list from client which we need to take reference to get data in SQL. Could you please help. 30-Oct 29-Jan AS Quarter1 30-Jan 30-Apr AS Quarter2 01-May 30-Jul AS Quarter3 31-Jul 29-Oct AS Quarter4 If today falls beween any of the quarter we need start date in date format for example if today is Jan/02/2018 then it shall return start date as '30-10-2017 00:00:00' and end date as '29-01-2018 00:00:00' if today is Dec/30/2017 then it shall return start date as '30-10-2017 00:00:00' and end date as '29-01-2018 00:00:00'
sql-server-2008sql-server-2005sql-server-2008-r2
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@aman6496 It is not clear what you actually need to happen. Do you need a function which returns the custom quarter range? Or is it something else? In any case it would make sense to create a table with 4 rows per each year period. Populate it with data for several years before and after this year, depending on your data requirements. This way you can always join to this table on the BETWEEN basis and figure out to which quarter any given date belongs.Please note that the ranges they gave you do not have the same number of days, i.e. first quarter has 92 while all others - 91. This means that their calendar is just a custom fiscal calendar which kinda mimics the standard calendar but begins on 30th of October. In other words, it is a calendar with full months, no full weeks.
1 Like 1 ·

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.