SQL Where Date > NOW and Less then now+14

I want to select all records where the date is greater than or equal to now and less than or equal to now +14 days?

0
Cassy01
9/15/2008 6:38:27 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
726 Views

Similar Articles

[PageSpeed] 46
Get it on Google Play
Get it on Apple App Store

you can either create a stored procedure (recommended) that does your date manipulation for you http://msdn.microsoft.com/en-us/library/ms186819.aspx

or pass your custom select string to your sqldatasource from your code behind such as

 

protected void Page_Load(object s,EventArgs e)
{
    if(!Page.IsPostBack)
       SqlDataSource1.SelectCommand  = "SELECT * FROM table where date Between '" + DateTime.Today.ToString("MM/dd/yyy") + "' AND '" + DateTime.Today.AddDays(14).ToString("MM/dd/yyyy") + "'";
}
  
Please mark post as answer
Obilit.com - Progressive Web Methodologies

My Blog
0
nvanhaaster
9/15/2008 6:45:13 PM

Depending on whether "now" equals today's date, or right now incl. the timestamp, your solution looks like either:

 1) If Now=Today, independent of what time today it is...

DECLARE @Today datetime
--strips off time and reverts to midnight, this might a clumsy way to do it...
SET @Today = CONVERT(datetime, CONVERT(varchar, GETDATE(),101))

DECLARE @TwoWeeksFromNow datetime
SET @TwoWeeksFromNow = CONVERT(datetime, CONVERT(varchar, DATEADD(d,14,GETDATE()),101))


SELECT
    DateID,
    @Today AS Today,
    @TwoWeeksFromNow AS TwoWeeksFromNow
FROM
    dbo.YourTable
WHERE
    DateID BETWEEN @Today AND @TwoWeeksFromNow
ORDER BY
    DateID

 

2) If now really means  right now, including timestamp, you can just do:

 SELECT
    DateID
FROM
    dbo.YourTable
WHERE
    DateID BETWEEN GETDATE() AND DATEADD(d,14,GETDATE())
ORDER BY
    DateID

 

Hope this helps!

0
augustlights
9/15/2008 6:52:31 PM
Reply:

Similar Artilces:

Get Date and compare with Date.Now in T-SQL
I am trying to set an alert to user for a project which will due on the particular date. How to compare the DateTime due date  which I get from the database with the Date.Now in stored procedure? Thanks in advance.Best regards,Ron. Make sure they are both in the same format. Many different ways to accomplish. The example below would convert both to a date: select * from table where convert(nvarchar(15),DueDate,101) = convert(nvarchar(15),Date.Now(),101) Thanks samsta, but I got an error when I am using Date.Now(). Then, I change with GetDate() function and works just ...

Sql Server 2000->->->->->Data->->->-> Sql Server 2005
How can i migrate data from Sql Server 2000 to  Sql Server 2000 A backup file of SQL 2000 can be restored on SQL 2005   ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Blog||Dub@i.net...

SQL > My SQL
I have a problem, my asp.net page wants to connect to the sql server, but it has to be the mysql. How can I solve this problem? This is my code: <%@ page explicit="true" language="VB" debug="true" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.Odbc" %> <%@ Import Namespace="System.Data.SqlClient" %> <html> <script runat="server"> sub page_load(sender as object, e as eventargs) If Not IsPostBack Then dim connect as sqlconnectio...

SQL Server Express >>> SQL Server
Hi SQL Server gurus I have developed a web-site using SQL Server Express -- mainly due to the open licence.  Now, when I look at the hosting companies, I see that some of them do not support SQL Server Express, allegedly due to performance issues.  Is this a valid argument?  In short, I am trying to find out whether SQL Server Express is good enough for me -- because it definitely seems to do what I want it to do -- OR should I be seriously thinking of upgrading as SQL Server Express will give me problems down the road?  Will it be able to take the load when site tr...

get DateTime.Now.Date in sql
 Hi, Im making an c# asp.net website. I use an dataset and an gridview.  I will fill an gridview with users with the follow sql query:SELECT     UserIdFROM         StatsWHERE     LunchDate =  DateTime.Now.Date()How can I get all the users with the date of today?I have try the follow solution but it doesnt work:SELECT     UserId FROM         Stats WHERE     LunchDate =  @LunchDateIn the objectDataSource I hav...

move from SQL 2000 to SQL 2005 Express now queries timeout all over the place
?is there that much difference?The DB I'm running is relatively small....I have a table with 40,000 records and doing a basic select query on one column is taking 30 to 40 secondswhere as on SQL 2000 it was taking fractions of a second   Anybody???anything?I'm at whits end with this problem...I've tried indexesI loaded the DB on my local development SQL and loaded in a massive script of queries into the DB Tuning Analyzer and it came back with no reccommendationsLocally the same process that's locking up runs in a matter of secondsSo I guess the only thing left to...

Applied SQL 2005 SP2, but now I can not install SQL profiler anymore. Any idea??
I have applied SQL 2005 SP2, but now I can not install SQL profiler anymore. Any idea?? Do I need to remove SQL and install again?? When I run SQL 2005 Dev and try to install profiler it says that it has been upgraded already. The box is unchecked, no profiler in bin folder... Also when running SP2 again can not install profiler... Rafal Zikbay.com - Free Classifieds (Search Over 5 mln jobs on Zikbay.com) DNN Direct ...

Recommendation
Hiya, I'm looking for some quick advice on how to achieve a task I've been trying to do. The situation: I run a script on my various SQL Servers (2000 and 2005). The script's output is an XML file. (I chose XML because the majority of the servers are on their own domains with different firewall rules and what not, so linking al servers was not an option). I also created an XSD file (booooooooring), which I still need to link to all the tables I created in a central SQL (for now 2000) Server. So I have an x-amount of XML files in a folder, and I will need to import those one by one. So f...

Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource
How can i rewrite this page so that i doesnt make use of an SqlDataSource?  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> ...

I created a website on my localhost with three .mdf files using SQL express but now I get an error when I try to host it on my web server without SQL express. need some help on how to change my connec
An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: An error has occurred whil...

error with Now() in SQL
In an ASP file using vbscript and JET 4.0:In the Access2000 database the date_added field is set as general date. Why does "SELECT * FROM  traffic_log WHERE date_added >= " & DateAdd("h",-24,Now()) produces a syntax error and "SELECT * FROM  traffic_log WHERE date_added >= " & DateAdd("h",-24,Date()) works fine ?? I need to retreive records added in the last 24hrs. In Access2000 both produce NO errors?? I only get this problem in vbscript??http://www.webcasinoguide.com use GetDate()Matthew M. Osbornhttp://blog.osbornm.com...

Problems SQL Server -> SQL Anywhere
We have a strange problem when moving from MS SQL Server to SQL Anywhere. Can anyone help us with this problem Environment: Windows XP Sp1 Visual C++ 6.0 Adaptive Server Anywhere 8.0 ODBC driver 8.00.01.2600 Problem: I have derived a recordset class from CRecordset, and is using bulk row fetching. The data from the database is fetched in batches of 25 rows (default recordset size). If I terminate the operation when x rows are handled, the remaining (25-x) rows will turn up in the first batch when I restart the operation. All is well so far, but the first batch will hold ...

Porting Informix -> MS SQL: date -> datetime problem
Hi. We have running an PB/Informix application. Now we need to run it against M$ SQL server too. We use date columns in Informix but there is only DateTime in the SQL server and datawindow doesn't manipulate with dates correctly... We don't want to have two application..., we don't want to have duplex datawindows... we don't want to change date to datetimes columns in Informix and rewrite all the application... I am looking for some "generic solution" which we should use. We are using PFC. Any ideas, similar issues? TIA Pepa **********...

SQL Server Reporting Services for SQL SERVER 2000 AND Visual Studio.NET 2005 .NET 2.0
Hi, Which version of SQl Server Reporting Services will work with SQL SERVER 2000 in pararrel with ASP.NET 2.0 (.NET 2.0 framework)?  Thanks, Azam HighOnCodingWanna get high! Hi, Okay I got the answer. Yes, we can use the SQL SERVER 2005 Reporting Services with SQL SERVER 2000. HighOnCodingWanna get high! ...

Web resources about - SQL Where Date > NOW and Less then now+14 - asp.net.sql-datasource

Resources last updated: 12/21/2015 9:22:41 AM