Solved

Useing between in asp

Posted on 2004-04-27
10
254 Views
Last Modified: 2010-04-06
I am trying to query into the rscheckuser return. What I am trying to do is only print records that are between 5 days back or 3 days ahead.
<%
dateth = DateAdd("d",3,Date())
dateba = Dateadd("d",-5,date())
%>
<%if rsCheckUser("Date") >= dateth then
=rsCheckUser("Date01") else%>

How would I write that.
0
Comment
Question by:eteran
[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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 10

Expert Comment

by:m8rix
ID: 10935833
Well for starters your code should look more like this:

<%
dateth = DateAdd("d",3,Date())
dateba = Dateadd("d",-5,date())
%>

<%
if rsCheckUser("Date") >= dateth And rsCheckUser("Date") <= dateba then
    'do whatever
else
    'do whatever
end if
%>

You may need to use "cdate(rsCheckUser("Date"))"

secondly it depends on if you only need to process data between those two dates. If so, then you should modify your SQL string to only retrieve the data you want.

hth
m8rix
0
 
LVL 6

Expert Comment

by:pkaleda
ID: 10938714
I agree with hth.  The best place to pull this is via the SQL string.  Only pull the data you want.
0
 
LVL 4

Expert Comment

by:kssaran
ID: 10946300
Hi

First of all you should not get all the records into the recordset and check if the date is with in the range or not as it consumes more resource and time if the number of records are more.

itz very simple. You can put the condition in the WHERE clause of the SELECT statement as follows

WHERE CONVERT(VARCHAR,datecolumn,112) >= CONVERT(VARCHAR,(Dateadd("d",-5,date())),112) AND  CONVERT(VARCHAR,datecolumn,112) <=  CONVERT(VARCHAR,(Dateadd("d",3,date())),112)


This will give you the best result at any condition

Rgds
Sara
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:m8rix
ID: 10946548
Sara, what you have just explained is the SQL string that pkaleda and myself have already recommended as a side note to the actual question asked.

Your welcome to join in the thread, but I wasn't sure if you realised this was the case as you didn't mention it.

reg's
m8rix
0
 
LVL 4

Expert Comment

by:kssaran
ID: 10946585
sorry abt writing it again without reading you guyz notes. But my solution certainly works. letuz wait for feed back from  eteran

Rgds
Sara
0
 
LVL 10

Accepted Solution

by:
m8rix earned 50 total points
ID: 10954372
This SQL also works if you require an SQL solution...
 
SELECT * FROM yourtable
WHERE (Date >= cdate('" & dateth & "')) AND (Date <= cdate('" & dateba & "'))
 
Now I know you said you only wanted to "print" the information between these dates, so don't use this method (or Sara's) if your process needs to access data outside your printed date range. If this is the case then I am sorry if we confused the situation.

reg's
m8rix
0
 

Author Comment

by:eteran
ID: 10965918
kssaran,
Can you exaploin the query in detail please like how it works.

WHERE CONVERT(VARCHAR,datecolumn,112) >= CONVERT(VARCHAR,(Dateadd("d",-5,date())),112) AND  CONVERT(VARCHAR,datecolumn,112) <=  CONVERT(VARCHAR,(Dateadd("d",3,date())),112)
 
0
 
LVL 11

Assisted Solution

by:sciber_dude
sciber_dude earned 200 total points
ID: 10973344
Going back to the question.... here is the solution as eteran wanted...

> I am trying to query into the rscheckuser return. What I am trying to do is only print records that are between 5 days back
> or 3 days ahead.
<%
dateth = DateAdd("d",3,Date())
dateba = Dateadd("d",-5,date())
%>
<%
if rsCheckUser("Date") >= dateth And rsCheckUser("Date") <= dateba then      ' from m8rix's solution
     ' =rsCheckUser("Date01")                                                <<< I think this is incorrect. (hence commented out)
     response.write rsCheckUser("Date01")                             ' << is correct (are u sure the field is called Date01?)
end if
%>

I dont think u can substitute "=" for "response.write" all the time

My 2 cents,
:) SD
0
 
LVL 11

Expert Comment

by:sciber_dude
ID: 10973350
@ eteran -

1. What is the database?
2. can u give us ur original SQL query so that it can be modified to ur requirements?

:) SD
0
 
LVL 4

Assisted Solution

by:kssaran
kssaran earned 250 total points
ID: 10973987
Hi eteran,

The query that i posted will conver the date into the format of YYYYMMDD and compare with the date range.

For example if there is a date as 10/10/2003 and the from and the to range is 01/10/2003 to 31/10/2003 Then the Query comparision will be

WHERE '20041010' >= '20041001' AND '20041010' <= '20041031'

Understood?

Rgds
Sara
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

756 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