Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:58:34+00:00 2026-06-06T05:58:34+00:00

Im trying to find a set of results in a database based on dates.

  • 0

Im trying to find a set of results in a database based on dates. The dates are stored as varchars in the format dd/mm/yyyy hh:mm:ss.

What i would like to do is search for all dates within a range of specified dates.

For example i tried:

SELECT * FROM table_name
WHERE fromDate BETWEEN LIKE '%12/06/2012%' AND LIKE '%16/06/2012%'

Is something like this possible or is there a better way of doing this type of statement, because so far i have had little success?

I’m using Microsoft SQL server 2008.

Peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:58:37+00:00Added an answer on June 6, 2026 at 5:58 am

    Since your date values also include time, you can’t use BETWEEN. The only safe way to do this is:

    SELECT <cols> FROM dbo.table_name
    WHERE CONVERT(DATE, fromDate, 103) >= '20120612' 
    AND CONVERT(DATE, fromDate, 103) < '20120617';
    

    But as Martin noticed, you’ll never be able to use an index on that column, so this will always perform a full table scan.

    If you really, really want to use BETWEEN, converting to DATE is the only safe way to do so (well, or trimming the time off in other, less efficient ways):

    SELECT <cols> FROM dbo.table_name
    WHERE CONVERT(DATE, fromDate, 103) BETWEEN '20120612' AND '20120616';
    

    But for consistency reasons I recommend against between even in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a simple database and I'm trying to find all users
Trying to use Zend_Search_Lucene to search a MySql database and display the results. Running
So I'm trying to find a way to return a very large result set
I am trying to find out how to set the windowless parameter to true,
I am trying to find an author in a set, and i am having
I'm trying to find a way to set a cookie that sets a user's
I am trying to find a way to set dict values encapsulated into a
I am trying to find the linear trend line for a set of data.
Hi I'm trying to find out if there is a way to set the
I'm trying to find all coverage_set_id with more than one benefit_id attached summary_attribute (value=2004687).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.