Solved

Sqldatasource WHERE with dates question

Posted on 2010-09-03
4
474 Views
Last Modified: 2012-05-10
I am trying to do something that I thought would be simple but it doesnt seem to be.  I have a date field stored in SQL.  I want to create a sqldatasource linked to a gridview with a where clause so it will only display the row if the date is within 7 days of the current date.  So as soon as the value is over a week old, it gets removed from the gridview.  I have tried everything I can think of but it either says I am comparing a date to a string or gives me syntax errors.  Can someone tell me how to do this?  Thank you.
0
Comment
Question by:mattpayne59
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
bouscal earned 500 total points
ID: 33599031
Your WHERE clause should read;

WHERE DATEDIFF(dd,yourdatefield,GETDATE()) < 7

0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33599174
0
 

Author Comment

by:mattpayne59
ID: 33599191
This is the statement I get from your instruction:

SELECT * FROM [IntakeID] WHERE (([Approved] IS NOT NULL) AND DATEDIFF(dd,ApprovedDate,GETDATE()) < 7

Can I use ApprovedDate like this or do I have to do it in a different way?  It is a valid SQL date field.  When I test this I get "Incorrect syntax near the keyword 'SET'." and I have no idea what that means.
0
 

Author Comment

by:mattpayne59
ID: 33599299
Forget it.  I had an extra ( in there.  This works great:

SELECT * FROM [IntakeID] WHERE  ([Approved] IS NOT NULL) AND DATEDIFF(dd,[ApprovedDate],GETDATE()) < 7

Thank you for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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