Solved

SQL Server Determine if date is recurrance date

Posted on 2016-10-26
3
54 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
ID: 41861034
<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
ID: 41861039
... 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
ID: 41861053
You answered my question correctly
I will have a follow-up question
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Query Optimization 14 45
TSQL query to generate xml 4 35
transaction in asp.net, sql server 6 33
SQL Server: Unable to remove duplicate sets in Header/Detail 6 25
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

803 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