Solved

Useing between in asp

Posted on 2004-04-27
10
247 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 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