Solved

Useing between in asp

Posted on 2004-04-27
10
223 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

747 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

9 Experts available now in Live!

Get 1:1 Help Now