How to select in between datetime in MSSQL?

Posted on 2009-04-16
Last Modified: 2012-06-21

I have a table need to select the data within a period.
For example, today is 2009-04-16, if I use the following SQL, it cannot select the data on 2009-04-16

If I change it to 2009-04-17, it can select. How should I write the SQL?

select * from transactions where transactiondatetime >='2009-04-10' and transactiondatetime <= '2009-04-16'

Open in new window

Question by:techques
    1 Comment
    LVL 39

    Accepted Solution

    select * from transactions where convert(varchar(10),transactiondatetime,111) >='2009/04/10' and convert(varchar(10),transactiondatetime,111) <= '2009/04/16'

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
    So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    759 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

    8 Experts available now in Live!

    Get 1:1 Help Now