Solved

t-sql date help

Posted on 2012-12-27
3
247 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

11 Experts available now in Live!

Get 1:1 Help Now