Click here to Skip to main content
11,928,078 members (31,025 online)
Click here to Skip to main content
Alternatives (1)
Add your own
alternative version

Tagged as


10 bookmarked

Accurate DATETIME Range Searching in SQL Server

, 9 Dec 2009 CPOL
When searching between datetimes in SQL(or SQL in a Stored Proc) we can't just do:select * from where CreateTime >= @DateFrom and CreateTime <= @DateToIf your search is date inclusive and you're not concerned with time, which most users aren't, then you need to add a little extra...


Members may post updates or alternatives to this current article in order to show different approaches or add new features.

1 Jul 2010
Chetan Patel
You can also get the correct result by passing time along with the date.ExampleIf you have to search records between 1st Apr 2010 and 5th Apr 2010, then:Select * from TableNameWhere DateField Between '04/01/2010 00:00:00' And '04/01/2010 23:59:59'


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mark Graham
Web Developer Currently working on projects for May Gurney
United Kingdom United Kingdom
Areas of expertise: c#,, design patterns, GUI useability/layout

| | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 9 Dec 2009
Article Copyright 2009 by Mark Graham
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid