Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 date range filter problem

Author  Topic 

bernike
Starting Member

1 Post

Posted - 2013-11-15 : 04:17:22
Hi, Im new to sql server and have a problem with date filter.
i have table like this:
----------------------------------
| shift | date 1 | date 2 |
==================================
| SI | 01/01/13 | 31/01/13 |
----------------------------------
| SII | 01/02/13 | 28/02/13 |
----------------------------------
| SIII | 01/03/13 | 31/03/13 |
----------------------------------

what is the syntax to get the Shift on 05/02/13?

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-11-15 : 05:25:22
DECLARE @date DATE = '05/02/13' -- Input date
SELECT *
FROM TableName
WHERE @DATE BETWEEN date1 AND date2


refer this link for implementing different types of date range filters in sql server
http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html




--
Chandu
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-11-15 : 05:29:46
If you face any difficulty with date formats let us know the data types of date1 and date2...

Support link for different types of date formats
http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-15 : 06:00:11
quote:
Originally posted by bandi

DECLARE @date DATE = '05/02/13' -- Input date
SELECT *
FROM TableName
WHERE @DATE BETWEEN date1 AND date2


refer this link for implementing different types of date range filters in sql server
http://visakhm.blogspot.in/2012/12/different-ways-to-implement-date-range.html




--
Chandu


Always try to pass date values in unambigous format.
See this

http://visakhm.blogspot.com/2011/12/why-iso-format-is-recommended-while.html

depending on your server settings the above date can be interpreted as 5th Feb 2013,2nd May 2013 0r 13th Feb 2005 so better not to rely upon that.


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -