Solved

select between dates microsoft sql / c#

Posted on 2006-11-12
3
268 Views
Last Modified: 2008-02-01
Cat get this select statement to work:
    string commandStr2 = "Select  *  From [Items] Where [ItemTypeID] = 1 AND ([ItemStartDate] between convert(datetime, '11/12/2004') and convert(datetime,'12/12/2007') )";

the string returns no results...

0
Comment
Question by:mosArt
3 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 125 total points
ID: 17926646
And if you run the same statement in query analyser?
Also, when using dates in string format, consider passing them in as YYYYMMDD HH:MM:SS - this will consistently work with ALL regional settings as it is ISO comp,iant.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 17926648
Hi mosArt,

have you tried :
    string commandStr2 = "Select  *  From [Items] Where [ItemTypeID] = 1 AND [ItemStartDate] between '2004/11/12' and '2007/12/12'";


Cheers!
0
 
LVL 4

Expert Comment

by:satish_nagdev
ID: 17927531
hi,
can you try following
   string commandStr2 = "Select  *  From [Items] Where [ItemTypeID] = 1 AND (convert(varchar,[ItemStartDate],103) between
convert(varchar, '11/12/2004',103) and convert(varchar,'12/12/2007',103) )";

thanks,
satish
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery autocomplete 10 68
Problem to page 4 74
Syntax error 9 45
How to hyperlink e.Rows.Cells[1].Text before it is displayed in the GridView control. 6 15
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

14 Experts available now in Live!

Get 1:1 Help Now