Help needed with asp date()

Trez

Solid State Member
Messages
8
Question:
I must display a series of 'special offers', each of which have a date. However, i must only display those offers which have dates that are still valid (ie the offer is still running). I currently have the code which accesses the DB..

<% set conn = server.createobject("ADODB.connection")
conn.open "banking", "Aut2006", "assign2"
sql = "SELECT * from specialOffer"
set rs = conn.execute(sql) %>

and in the xhtml body have..

<%

If CDate(RS("fromDate")) <= CDate(Now) and CDate(RS("toDate")) >= CDate(Now)
Then
response.write ("<p class="specials"> = rs('ShortDesc')</p>")

end if

%>

But not working, could anyone help with this? Thanks

-Trez
 
OK the trouble is that once you've gotten the data from the database it's just a string.

therefor.
01/06/2006 is less than
02/06/2005 because the most significant digit in the second data (2) is greater than the most significant digit from the first date (1).

you need to edit the sql statement to do the selecting for you.

sql = "select * from specaloffer where fromdate <= Cdate(now) AND todate >= cDate(now)"

(that will only select offeres where the dates are valid (assuming that the fields are set as date fields and not text fields in the databse).
 
Back
Top Bottom