Solved

Sqldatasource WHERE with dates question

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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