• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

select between dates microsoft sql / c#

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
mosArt
Asked:
mosArt
1 Solution
 
NightmanCTOCommented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
satish_nagdevCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now