asp date range search

Results 1 to 2 of 2

Thread: asp date range search

  1. #1
    Join Date
    Dec 1969

    Default asp date range search

    I&#039;m trying to search for records from a SQL database, and display those that appear in a certain range. The user enteres the dates in a form (in the formate 01/31/2003). A begin and and end date are entered. The database has a field with the date (stored as Jan 31 2003. I&#039;m having endless trouble with &#039;type mismatch&#039; errors, and the logic for the search. All help and comments greatly appreciated.<BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default Not at all advanced

    This is a basic SQL question. The answer depends (a lot) on whether the field in the DB has *just* a date value or sometimes (or always) holds a date and time.<BR><BR>If it&#039;s just a date value, then the answer is dirt easy:<BR><BR>SELECT * FROM table WHERE datefield BETWEEN &#039;1/31/2003&#039; AND &#039;2/23/2003&#039;<BR><BR>If it&#039;s a combo date/time, then that query will miss values on the last date of the range unless their time is midnight.<BR><BR>So then it&#039;s better to do:<BR><BR>SELECT * FROM table WHERE datefield &#062;= &#039;1/31/2003&#039; AND datefield &#060; &#039;2/24/2003&#039;<BR><BR>Note that I increased the end date by one. But then used &#060; instead of &#060;=.<BR><BR>Anyway, next time post basic database questions in the DATABASE forum and basic non-database questions in the general Q&A forum. READ the rules for what constitutes an ADVANCED posting, which this one was not.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts