If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Recurring time frames

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-03-07, 15:05
Oddish Oddish is offline
Registered User
 
Join Date: Mar 2003
Posts: 43
Recurring time frames

I've got a bunch of banners that I want to schedule during different times every year, but I'm having trouble figuring out the sql query for fetching the correct banners. Every banner has a column for "start_date" and one for "end_date" and the rows could look like this:

Code:
 start_date  |  end_date
 -------------------------
 2000-01-01  |  NULL
 2000-10-01  |  2000-05-01
 2000-05-01  |  2000-01-01
The year is irrelevant here, since these banners should be recurring during certain periods, every year.

The first row has no end date, so that should always be active
The second row (October 1st - May 1st) should not be active
The third row (May 1st - January 1st) should be active

I don't have the sql knowledge to put this logic into a query though, and I was hoping to get some pointers from the experts here. I've fooled around with CASE statements that involved different sets of conditions depending on whether the start month was larger or smaller than the end month, but I never got anywhere.

Thanks very much in advance for any help you can give me!
Reply With Quote
  #2 (permalink)  
Old 05-03-07, 19:53
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Code:
SELECT
banner
FROM 
yourtable
WHERE
month(current_date) 
BETWEEN
month(startdate) AND month(enddate)
you can of course add the qualifying day clauses in there as well if banners have start/end dates other than the first of the month.

if you don't have the days, then really all you need is a start month and end month in a tinyint column for each.
Reply With Quote
  #3 (permalink)  
Old 05-03-07, 20:46
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
also, don't do what your sample data shows --

2000-10-01 | 2000-05-01

that's not gonna satisfy any BETWEEN range test properly, so you will want to change it to this --

2000-10-01 | 2000-12-01
2000-01-01 | 2000-05-01

can you see why?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 05-04-07, 11:44
Oddish Oddish is offline
Registered User
 
Join Date: Mar 2003
Posts: 43
Quote:
Originally Posted by r937
also, don't do what your sample data shows --

2000-10-01 | 2000-05-01

that's not gonna satisfy any BETWEEN range test properly, so you will want to change it to this --

2000-10-01 | 2000-12-01
2000-01-01 | 2000-05-01

can you see why?

I guess I thought I could get away with just one date range per banner, even though it might overlap a year. I guess I'll have to make some changes.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On