Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the next date

Status
Not open for further replies.

Craigieboy

Programmer
May 25, 2001
71
GB
Hi ASP friends,

This one is driving me a little mad and I know it shouldn't be.

Using a SQL statement I am required to find the next day's date from the one the user would input into a form. In Query Analyzer I can get the exact result I am looking for. My query is this -

DECLARE @mydate SMALLDATETIME
SET @mydate = '28-Feb-2002'
SELECT @mydate
SELECT DATEADD(d,1,@mydate) AS thenextday

(a copy and paste into QA will show you it working)

Now, when I move this into ASP I can't seem to pull out my result and display it on my page. Can someone tell me what I'm doing wrong. Here is my ASP code:

startdate = "28-Feb-2002" (or whatever the user input was)

sql = "DECLARE @mydate SMALLDATETIME SET @mydate ='" & startdate & "' SELECT DATEADD(d,1,@mydate) AS nextday FROM tbl_template_check"

Set inetRS = oConn.Execute(sql)

My problem is now the display part. The result of this query is 1-Mar-2002. How do I display this, perhaps using a Response.Write?

Any help would be really appreciated.

Many thanks in advance,
Craig
 
Thanks for your response jamieslover. I did try this before making my post as you would think it's the most straight forward line to write in this instance.

Unfortunately it didn't work this time :-(

However, my persistance came up with this, which is now producing my desired results:

startdate = "31-Mar-2002" (or whatever the user input was)

sql = "DECLARE @mydate SMALLDATETIME SET @mydate = '" & startdate & "'"
Set inetRS = oConn.Execute(sql)

Response.Write DateAdd("d", 1, startdate)

I have shortened my SQL query and moved the DATEADD into the Response.Write and bingo!

Thanks again for taking the time to respond to my post.

Regards,
Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top