Click here to Skip to main content
Click here to Skip to main content
Alternatives (1)

Tagged as

Go to top

Accurate DATETIME Range Searching in SQL Server

, 9 Dec 2009
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...

Alternatives

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'

License

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

Share

About the Author

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

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