## Computing First paydate of quarter

 Author Message bgsxygrmn SSC Journeyman Group: General Forum Members Points: 87 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 SSC-Forever Group: General Forum Members Points: 46453 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. RonPlease help us, help you -before posting a question please read Before posting a performance problem please read bgsxygrmn SSC Journeyman Group: General Forum Members Points: 87 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 SSC-Forever Group: General Forum Members Points: 48526 Visits: 11933 `declare @FirstPayDate datetimeset @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') ) aorder by a.Date`Results:`Date FirstPayDateOfCurrentQuarter----------------------- ----------------------------2010-07-27 00:00:00.000 2010-07-02 00:00:00.0002010-08-27 00:00:00.000 2010-07-02 00:00:00.0002010-10-01 00:00:00.000 2010-10-08 00:00:00.000(3 row(s) affected)` bitbucket-25253 SSC-Forever Group: General Forum Members Points: 46453 Visits: 25280 bgsxygrmnThanks, 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 themselvesPlease 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. RonPlease help us, help you -before posting a question please read Before posting a performance problem please read bgsxygrmn SSC Journeyman Group: General Forum Members Points: 87 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 SSCoach Group: General Forum Members Points: 15552 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 questionHow to post performance problemsTally 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."

## 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
 SQL Server 2017      SQL Server 2017 - Administration      SQL Server 2017 - Development SQL Server 2016      SQL Server 2016 - Administration      SQL Server 2016 - Development and T-SQL SQL Server 2014      Administration - SQL Server 2014      Development - SQL Server 2014 SQL Server 2012      SQL 2012 - General      SQL Server 2012 - T-SQL SQL Server vNext      SQL Server 15 - Administration      SQL Server 15 - Development SQL Server 2008      SQL Server 2008 - General      T-SQL (SS2K8)      June 2007 CTP      Working with Oracle      July CTP      SQL Server Newbies      Security (SS2K8)      SQL Server 2008 High Availability      SQL Server 2008 Administration      Data Corruption (SS2K8 / SS2K8 R2)      SQL Server 2008 Performance Tuning Cloud Computing      SQL Azure - Development      SQL Azure - Administration      Amazon AWS and other cloud vendors      General Cloud Computing Questions      CosmosDB      Azure Data Lake      Azure Machine Learning Reporting Services      Reporting Services      Reporting Services 2005 Administration      Reporting Services 2005 Development      Reporting Services 2008/R2 Administration      Reporting Services 2008 Development      SSRS 2012      SSRS 2014      SSRS 2016 Programming      Connecting      General      SMO/RMO/DMO      XML      Service Broker      Powershell      Testing      TFS/Data Dude/DBPro      SSDT      Continuous Integration, Deployment, and Delivery      R Services and R Language Data Warehousing      Integration Services      Strategies and Ideas      Analysis Services      Data Transformation Services (DTS)      Performance Point      Data Mining      PowerPivot      R language      Machine Learning Database Design      Disaster Recovery      Design Ideas and Questions      Relational Theory      Hardware      Virtualization      Security and Auditing SQLServerCentral.com      Anything that is NOT about SQL!      Contests!      Editorials      SQLServerCentral.com Announcements      SQLServerCentral.com Website Issues      Suggestions      Tag Issues with Content      Podcast Feedback      SQLServerCentral.com Test Forum      Articles Requested SQL Server 2005      Administering      Backups      Business Intelligence      CLR Integration and Programming.      Data Corruption      Development      Working with Oracle      SQL Server 2005 Compact Edition      SQL Server 2005 General Discussion      SQL Server 2005 Security      SQL Server 2005 Strategies      SS2K5 Replication      SQL Server Express      SQL Server 2005 Performance Tuning      SQL Server 2005 Integration Services      T-SQL (SS2K5)      SQL Server Newbies SQL Server 7,2000      Administration      Backups      Data Corruption      General      Globalization      In The Enterprise      Working with Oracle      Security      Strategies      SQL Server Newbies      Service Packs      SQL Server CE      Performance Tuning      Replication      Sarbanes-Oxley      T-SQL      SQL Server Agent SQL Server and other platforms      MySQL      Oracle      PostgreSQL      DB2      SQL Server and Sharepoint Older Versions of SQL (v6.5, v6.0, v4.2)      Older Versions of SQL (v6.5, v6.0, v4.2) Career      Certification      Employers and Employees      Events      Job Postings      Resumes and Job Hunters      Presentations and Speaking      Retired Members Testing Center      Question of the Day (QOD)      SQL Server Security Skills Microsoft Access      Microsoft Access Products and Books      Third Party Products         CA         SQLCentric         Extreme Technologies.         Innovartis         Embarcadero         Sonasoft         Golden Gate Software         Idera         Lumigent         Red Gate Software         Quest Software         ApexSQL         SQL Sentry      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss Data Warehousing Books          Discuss T-SQL Books          Discuss DTS Books          Discuss SQL Server 2000 Books         Discuss SQL Server 7.0 Books Notification Services      Administration Article Discussions Future Versions      SQL 12