SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Computing First paydate of quarter


Computing First paydate of quarter

Author
Message
bgsxygrmn
bgsxygrmn
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 46
Can anyone help me compute the first paydate of the current quarter? This is assuming that there's 14 day intervals for paydates and 1/1/2010 is a paydate.

So say the current date is july 27th 2010. The first paydate of the quarter would be july 2nd 2010.

Can anyone help?

Thanks
bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7797 Visits: 25280
Go here I am sure you can find what you need.
https://www.sqlservercentral.com/blogs/lynnpettis/archive/2009/03/25/some-common-date-routines.aspx

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
bgsxygrmn
bgsxygrmn
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 46
Thanks, but that doesn't really help me at all. I think that I would have to combine two of the functions that are listed in the link.
Michael Valentine Jones
Michael Valentine Jones
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5708 Visits: 11771

declare @FirstPayDate datetime
set @FirstPayDate = '20100101'

select
*,
FirstPayDateOfCurrentQuarter =
dateadd(dd,(datediff(dd,@FirstPayDate,dateadd(dd,13,
dateadd(qq,datediff(qq,@FirstPayDate,Date),@FirstPayDate)))/14)*14,@FirstPayDate)
from
(
select Date = convert(datetime,'20100727') union all
select Date = convert(datetime,'20100827') union all
select Date = convert(datetime,'20101001')
) a
order by
a.Date


Results:

Date FirstPayDateOfCurrentQuarter
----------------------- ----------------------------
2010-07-27 00:00:00.000 2010-07-02 00:00:00.000
2010-08-27 00:00:00.000 2010-07-02 00:00:00.000
2010-10-01 00:00:00.000 2010-10-08 00:00:00.000

(3 row(s) affected)

bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)SSCertifiable (7.8K reputation)

Group: General Forum Members
Points: 7797 Visits: 25280
bgsxygrmn
Thanks, but that doesn't really help me at all. I think that I would have to combine two of the functions that are listed in the link.


Do not understand your:
that doesn't really help me at all.


You want someone to give you the complete T-SQL statement?

Remember People here help those who help themselves

Please read the first link in my signature block for the correct procedure to post a question, paying particular attention to table definition, sample data, expected results and what you have done

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
bgsxygrmn
bgsxygrmn
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 46
Thanks Michael,

That did the trick. I edited your code to:


select dateadd(dd,(datediff(dd,'1/1/2010',dateadd(dd,13,
dateadd(qq,datediff(qq,'1/1/2010',getdate()),'1/1/2010')))/14)*14,'1/1/2010')

and that worked perfectly. I don't think that I would have figured it out just using one dateadd and one datediff
jcrawf02
jcrawf02
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2238 Visits: 19324
option: add it to a calendar table, logging which days are paydates.

Similar stuff: http://jasonbrimhall.info/?p=193

---------------------------------------------------------
How best to post your question
How to post performance problems
Tally Table:What it is and how it replaces a loop

"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search