Solved

SQL Server Determine if date is recurrance date

Posted on 2016-10-26
3
36 Views
Last Modified: 2016-10-26
I need to determine if GETDATE()  is exactly on a two week interval from a specific date

Example...
A person has a payment to make
First Payment was on July 20th 2010
Interval is Bi-Weekly (Every 2 weeks)

Is today THAT "every 14 days" date? Yes/No
0
Comment
Question by:lrbrister
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
Comment Utility
<Air code.  I do my own stunts too>

SELECT CASE 
  WHEN DATEADD(d, 14, FirstPaymentDate) = CAST(GETDATE() as date) THEN 'Yes'
  ELSE 'No' END as MakeUpAColumnNameHere

Open in new window

0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
... or if we're talking 'If this is on the 14th date somewhere out in the future' then use Modulo...

SELECT CASE 
  WHEN DATEDIFF(d, FirstPaymentDate, CAST(GETDATE() as date)) % 14 = 0 THEN 'Yes'
  ELSE 'No' END as MakeUpAColumnNameHere

Open in new window

0
 

Author Closing Comment

by:lrbrister
Comment Utility
You answered my question correctly
I will have a follow-up question
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now