Asim Zaidi
Asim Zaidi

Reputation: 28284

date query between two dates

in my table I have this schema

record      startDate    endDate
abs         2005-11-29   2005-11-21
absasd          2005-11-23   2005-01-22
absty           2005-10-26   2005-02-23
absfx           2005-09-27   2005-09-24
absft           2005-10-28   2005-07-25
absyh           2005-01-28   2005-08-01
absdx           2005-12-29   2005-01-02
abs345          2005-06-24   2005-02-03
abser           2005-07-14   2005-04-06
absbv       2005-08-01   2005-05-08
abse        2005-07-12   2005-06-09
abserr          2005-12-30   2005-07-14
absf        2005-01-12   2005-12-16
abscv           2005-04-11   2005-12-26
abscv           2005-06-01   2005-11-27
absc        2005-07-03   2005-10-28
absv        2005-07-06   2005-09-25
.....
.....
......

I want to select all records that fall between 2005-01-01 and 2005-10-01. and certain other dates. What would be the sql for that.

Upvotes: 0

Views: 868

Answers (2)

Praveen Lobo
Praveen Lobo

Reputation: 7187

With a reputation of 1K+ and this question? Are you alright? :-)

SELECT * FROM TableName
WHERE startDate > '2005-01-01' and startDate < '2005-10-01'
--WHERE startDate > '2005-01-01' and endDate < '2005-10-01'
--WHERE endDate > '2005-01-01' and endDate < '2005-10-01'
--WHERE endDate > '2005-01-01' and startDate < '2005-10-01'
--WHERE (startDate > '2005-01-01' and startDate < '2005-10-01' ) OR (endDate > '2005-01-01' and endDate < '2005-10-01')
--WHERE (startDate > '2005-01-01' and startDate < '2005-10-01' ) AND (endDate > '2005-01-01' and endDate < '2005-10-01')

Upvotes: 1

Joe Stefanelli
Joe Stefanelli

Reputation: 135739

SELECT *
    FROM YourTable
    WHERE startDate >= '2005-01-01'
        AND endDate <= '2005-10-01'

Upvotes: 4

Related Questions