Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If then statement help needed.

Status
Not open for further replies.

TheCount

Programmer
Oct 24, 2001
64
NL
I have the following problem:
This is my statement and rsCommon("SMD") is an date.

Code:
if DateDiff("m", now, rsCommon("SMD")) >= -3 and DateDiff("m", now, rsCommon("SMD")) <= -6 then
  Response.write("<tr>") & vbCrLF
  Response.write("<td>" & rsCommon("username") & "</td>") & vbCrLF
  Response.write("<td> 3 m On </td>") & vbCrLF
  Response.write("<td>" & DateAdd(("m"), 3, (rsCommon("SMD"))) & "</td>") & vbCrLF
  Response.write("</tr>") & vbCrLF
 end if

The date today is 11-december-2004 and the SMD = 09-september-2004
In the code i check if the SMD(date) is between 3 months and 6 months ago.
This statement above doesn't give me an response while it should be.
Maybe because it's weekend now i don't see it clearly but the if clause should result an true statement.

HELP!

 
No i need the AND.

I do a query on a database, and want to do the following with the recordset.

do something if data = between 2 weeks and 3 months ago
do something if data = between 3 months and 6 months ago
do something if data = between 6 months and 1 year ago
do something if data = between 1 year and 2 years ago


 
There is no error. It wont give me any result while
i put a few testitems in the database with a date between now and 3-4 months ago.
In the code i check if the SMD(date) is between 3 months and 6 months ago.
This statement above doesn't give me an response while it should be.
 
Try this:

if rsCommon("SMD") >= DateDiff("m", now, rsCommon("SMD"))-3 and rsCommon("SMD)<=DateDiff("m", now, rsCommon("SMD"))-6 then


-L
 
oops...i meant something like this

if Month(rsCommon("SMD")) >= DateDiff("m", now, rsCommon("SMD"))-3 and Month(rsCommon("SMD))<=DateDiff("m", now, rsCommon("SMD"))-6 then

-L
 
I had thought about that too, but the problem with that is :

Let say SMD = 10-september-2003 then the result of month gives me september.
Today it is 11-december-2004 so a compare with that and datediff("m", now, rsCommon("SMD"))-3 gives me true. But it was in the year 2003 and not 2004 so it is 15 months ago and not 3 months ago.
 
If you use >= and <= for each test, the first match to the EQUALS will return that result. That means for each condition, you should probably use only one equals on the same end of the test, either a <= or a >= for each one:

do something if data = >= 2 weeks and < 3 months ago
do something if data = >= 3 months and < 6 months ago
do something if data = >= 6 months and < 12 months ago
do something if data = >= 12 months and < 24 months ago

Lee

 
Thanks i gona try the suggestions tommorow, and turn back here to tell if it work ro not
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top