SQL Query Date help

Posted on 2011-11-01
Last Modified: 2012-06-27
Hello there,

i want to filter my sql server 2005 table based on datetime,so i do something like this but it does not return any rows

WHERE productid=6618 and created >= 2011-09-23 and created < = 2011-10-22

please help.

Question by:zolf
    LVL 3

    Accepted Solution


    First of all the dates should be in ''...

    This this combination:

    WHERE productid=6618 and created >= '23sep2011' and created <= '22oct2011'

    Open in new window

    LVL 8

    Assisted Solution

    Write as follows :

    WHERE productid=6618 and CONVERT(nvarchar(10), created, 111) >= CONVERT(nvarchar(10), '2011-09-23', 111) and CONVERT(nvarchar(10), created, 111) < = CONVERT(nvarchar(10), '2011-10-22', 111)

    LVL 9

    Assisted Solution

    Try this

    WHERE productid=6618 and created >= convert(datetime,'2011-09-23') and created < = convert(datetime,'2011-10-22')

    Open in new window


    WHERE productid=6618 and created between convert(datetime,'2011-09-23') and convert(datetime,'2011-10-22')

    Open in new window

    LVL 50

    Assisted Solution

    WHERE productid=6618 and created between '20110923 00:00:00.000'  and '20111022 23:59:59.997'

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now