Solved

Sqldatasource WHERE with dates question

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

706 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

18 Experts available now in Live!

Get 1:1 Help Now