Solved

t-sql date help

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

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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

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…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

696 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