kmccollum
asked on
Find month in date range
I need to build a SQL query that will return all entries where a specified month is in a date range on the record.
I have a to and from date on the record and want to find all that cover May 2012 for example.
Thanks
I have a to and from date on the record and want to find all that cover May 2012 for example.
Thanks
ASKER
Kent,
Not really what I have is a date range and I want to find if May 2012 is in that range,
Example...
Start Date = 01/21/2001
End Date = 01/21/2013
This would return because may 2012 is in the date range
however
start date = 01/21/2001
end date = 01/21/2011
this would not return because may 2012 is past the end date
I am trying to see if 05/2012 is between (Sdate) and (Edate)
thanks,
Kevin
Not really what I have is a date range and I want to find if May 2012 is in that range,
Example...
Start Date = 01/21/2001
End Date = 01/21/2013
This would return because may 2012 is in the date range
however
start date = 01/21/2001
end date = 01/21/2011
this would not return because may 2012 is past the end date
I am trying to see if 05/2012 is between (Sdate) and (Edate)
thanks,
Kevin
Assuming the fromDate is always less than or equal to the toDate, then determining if those dates cover May 2012 is essentially this:
HTH,
DaveSlash
select *
from MyTable
where (fromDate between '2012-05-01' and '2012-05-01')
or (toDate between '2012-05-01' and '2012-05-31')
HTH,
DaveSlash
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, that would give the start date's in may or the end date's in may but not the date ranges that cover may
example 1 above would not return with this query.
example 1 above would not return with this query.
> but not the date ranges that cover may
My second query would.
My second query would.
I'm not really sure what you asking, but date manipulation is very easy in DB2.
SELECT * FROM mytable WHERE year(somedate)=2012 AND month(somedate)=5;
The query above will get all rows where somedate is in May of 2012. Will that work for you?
Kent