Home > ASP Development > How can I select a range of dates?

How can I select a range of dates?



I want to select release dates from a large table and have it so my script only displays release dates PAST the current date.



My script looks something like this but it's obviously wrong...




Code:



sql = "SELECT * FROM searchtable WHERE console = '"& console &"' and release > "& date() &" ORDER BY release ASC"






The field "release" is set as a varchar with values such as 9/10/2005

    
Guest


You are better off changing release to be a datetime field... however, this may work


Code:


sql = "SELECT * FROM searchtable WHERE console = '"& console &"' and CAST(release AS DateTime) > '"& date() &"' ORDER BY CAST(release AS DateTime) ASC"




Not completely sure though - and you will definately get an error if any of the values in release cannot be converted to a date

Was this answer helpful ? Yes No   
Guest


ok, i changed the field to a date instead and the scripts running but it's displaying ALL release's instead of the ones after today.

Was this answer helpful ? Yes No   
Guest


Can you post your latest sql please

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by elijathegold
Can you post your latest sql please








and to add if it comes to it....write out the sql statement to see the values by:



response.write sql

response.end



BEFORE the sql is opened/executed

Was this answer helpful ? Yes No   
Guest


response.write=



SELECT * FROM searchtable WHERE console = 'pc' AND release > 7/21/2005 ORDER BY release ASC



coding...




Code:


sql = "SELECT * FROM searchtable WHERE console = '"& console &"' AND release > "& date() &" ORDER BY release ASC"



Was this answer helpful ? Yes No   
Guest


try this

Code:


sql = "SELECT * FROM searchtable WHERE console = '"& console &"' AND release > '"& date() &"' ORDER BY release ASC"



Was this answer helpful ? Yes No   
Guest


you need single quotes around your date variable:


Code:



sql = "SELECT * FROM searchtable WHERE console = '"& console &"' AND release > '"& date() &"' ORDER BY release ASC"






yeah, what he said ...

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by mehere
you need single quotes around your date variable:


Code:



sql = "SELECT * FROM searchtable WHERE console = '"& console &"' AND release > '"& date() &"' ORDER BY release ASC"






yeah, what he said ...






single for ms sql # for access

Was this answer helpful ? Yes No   
Guest


hmmmmmmmm, it's still listing all the release dates...



I only have the two to test out the script...



10/20/2002

12/20/2010



and they're both showing

Was this answer helpful ? Yes No   
Guest
Answer it
Ask Question About ASP Development
 

Programming

Related Pages

 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved