Solved

Useing between in asp

Posted on 2004-04-27
10
230 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

932 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

10 Experts available now in Live!

Get 1:1 Help Now