I have table with two columns (startdate & enddate) and I have two submission dates (2012-02-29 & 2012-03-30) I am trying to get the data between startdate (2012-02-29) and the enddate (2012-03-30)
I've tried
i.startdate between '2012-02-29' and i.enddate '2012-03-30'
but that didnt work, I've been googling this for hours with no clear answer, any help would be appreciated, thanks in advance.
If I understand correctly:
- Your table contains two date fields,
StartDate
and EndDate
, that describe a lengthy event.
- You want to find all the events that fall completely within the period described by two other dates, in this case
2012-02-29
and 2012-03-30
.
If this is correct then use this:
SELECT * FROM Events
WHERE StartDate >= '2012-02-29' AND EndDate <= '2012-03-30';
SELECT * FROM table_with_dates WHERE (i.startdate BETWEEN '2012-02-29' AND '2012-03-30') AND (i.enddate BETWEEN '2012-02-29' AND '2012-03-30')
where ('2012-02-29' between i.startdate and i.enddate) and ('2012-03-30' between i.startdate and i.enddate)
I understand that you want both your submissions (two dates) between startdate and enddate?
so
Where (@firstDate between StartDate and EndDate) and (@secondDate between StartDate and EndDate)
Since the startdate and enddate are separate fields and you are looking for specific startdates and enddates you don't really need a between, just a
select ..... from ..... where i.startdate >= '2012-02-29' and i.enddate =< '2012-03-30'