Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

MySQL query help?

My table name is "Location" and I need to select the off season message if the current date is outside the season.

My table structure is

location_id (int)

season_start (date)

season_end (date)

offseason_message (text)

The row I'm dealing with is for Location 1.

location_id = 1

season_start = 2016-04-15

season_end = 2015-09-30

offseason_message = "This location is currently closed. The season starts April 15"

I want to return the off season message if today's date is outside of the range, and return 0 results if today's date is within the range.

The season dates will be updated every year to show the appropriate dates. I'm wondering if I would be better off having the end date be the end of last season until the start of the new season. So currently it would be season_start=2016-04-15 and season_end=2015-09-30.

1 Answer

Relevance
  • Jeff P
    Lv 7
    5 years ago
    Favorite Answer

    I would swap the start/end dates. Have the start date be the first date of the season (2015-09-30) and the end date be the last day of the season (2016-04-15).

    In order to get the off-season messages, you simply need to add a NOT BETWEEN to your WHERE clause to find dates NOT BETWEEN your season_start date and season_end date:

    SELECT offseason_message

    FROM locations

    WHERE location_id = 1 AND CURRENT_DATE NOT BETWEEN season_start AND season_end;

Still have questions? Get your answers by asking now.