Wednesday, March 7, 2012

Events for Selected Month

I know how to get the events that start say on May, and I know how to get the events that end on May, however, How would I get the events that start on January and end in July. The month of May should display that event too.

so far,as an example, I have:

SELECTEvents.startDate,Events.endDateFROM EventsWHEREEvents.Active = 1ANDstartDateBETWEENconvert(smalldatetime,'5/1/2006')ANDconvert(smalldatetime,'5/31/2006')ORDER BY Events.startDateASC;
 
thank in advance.

Ty this using Month function of your datatime filed.

WHERE
Events.Active = 1
ANDMONTH(startDate)BETWEEN 1AND7

Or

WHERE
Events.Active = 1
AND
(Month(startDate)>0 and Month(startdate)<8)

|||

the months will be depend on the event. In other words I just said January and July but it could be anything. Can the one and seven be wildcards or maybe 1 and 12 to cover the entire year?

|||

Yes, you can do


Events.Active = 1
AND
(Month(startDate)>0 and Month(startdate)<12)

Or you can cover the year like this:

Year(startDate)=2006 --for year 2006 or any year you can change.

This only takes care of your event start date. In the same logic, you can do something to the event end date if you have one.

Let me know if you need more information.

No comments:

Post a Comment