Solved

t-sql date help

Posted on 2012-12-27
3
250 Views
Last Modified: 2012-12-27
I need help on t-sql date:

I have this: DATEDIFF(DAY,StartDate, getdate())  =  '14' to find the startdate is 14 days pass.

 then I also need to find those that occur every 7 days thereafter, etc 21 days, 28 days, 35 days

Can someone please help?

Thank you!!
0
Comment
Question by:jfreeman2010
3 Comments
 
LVL 21

Assisted Solution

by:mcsween
mcsween earned 250 total points
ID: 38724189
WHERE (datediff(day,StartDate,getdate()) % 7 = 0)

Open in new window


This will get any where the result from your datediff function divides evenly by 7
0
 
LVL 15

Accepted Solution

by:
tim_cs earned 250 total points
ID: 38724193
How about something like this.

WHERE
   DATEDIFF(DAY,startDate,getdate()) = 14 OR (DATEDIFF(DAY,startDate,getdate())  > 14 AND DATEDIFF(DAY,startDate,getdate())%7 = 0)
0
 

Author Comment

by:jfreeman2010
ID: 38724231
yes, it works.  Thank you very much!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL Stored Procedure - Search multiple tables (Single column) for similar values 7 62
SQL Maintenance Plan 3 30
In or Between 2 44
MSSQL Speen Degradation 4 9
I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

17 Experts available now in Live!

Get 1:1 Help Now