Solved

Useing between in asp

Posted on 2004-04-27
10
237 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple PHP - search by location postcode/zip code 8 33
Problem with Connection / Parameter: 4 21
use of cookies and regulations 1 86
Select distinct 25 97
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…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now