Solved

Sqldatasource WHERE with dates question

Posted on 2010-09-03
4
478 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

630 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