Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:28:04+00:00 2026-06-03T05:28:04+00:00

Okay, I feel like I should be able to do this, but I have

  • 0

Okay, I feel like I should be able to do this, but I have searched to no avail.

I need to show one of two different data sets depending on what day of the year it is. Specifically, if today is October 31 (or earlier,) I want to pull all entries from October 1 of last year to the end of current year. If today is after October 31, I want my data set to show entries from October 1 of the current year to the end of next year.

The code below is creating a simple “calendar” table variable that is storing all the months that exist in a specific dataset. Right now I am just limiting it to dates for current year. I would like to replace that with code to allow it to function as I stated above. I thought of using an IF statement, but I cannot figure out how to compare with getdate() day and month only.

DECLARE @calendar TABLE 
(       mon_name    VARCHAR(10)
    ,   mon_number  INT
    ,   yr          INT
)

INSERT INTO @calendar
SELECT      DATENAME(m,departure_date)
        ,   MONTH(departure_date)
        ,   YEAR(departure_date)
FROM        trip_mission
WHERE       departure_date          <>'1/1/1900' 
AND         YEAR(departure_date)    = YEAR(getdate())
GROUP BY    DATENAME(m,departure_date)
        ,   MONTH(departure_date)
        ,   YEAR(departure_date)

A simplified form of the question may be how can I run some code only if today is <= October 31. It would be super easy if I could say <= October 31, 2012, but I need it to be dynamic so that it will flip over every year.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:28:05+00:00Added an answer on June 3, 2026 at 5:28 am

    The following little trick will allow you to select different subsets based on what month it is:

    WHERE departure_date >= DATEADD(
      YEAR,
      MONTH(GETDATE()) / 11 - 1,
      CAST(YEAR(GETDATE()) AS char(4)) + '1001'
    )
    

    The last argument forms the date of the 1st of October of the current year. The second argument controls whether we subtract 1 year or not. Assuming the current year to be 2012, here’s what we get depending on the current month

    Current month  MONTH(GETDATE())  MONTH(…) / 11  MONTH(…) / 11 - 1  DATEADD(…)
    -------------  ----------------  -------------  -----------------  ----------
    January        1                 0              -1                 2011-10-01
    February       2                 0              -1                 2011-10-01
    March          3                 0              -1                 2011-10-01
    April          4                 0              -1                 2011-10-01
    May            5                 0              -1                 2011-10-01
    June           6                 0              -1                 2011-10-01
    July           7                 0              -1                 2011-10-01
    August         8                 0              -1                 2011-10-01
    September      9                 0              -1                 2011-10-01
    October        10                0              -1                 2011-10-01
    November       11                1              0                  2012-10-01
    December       12                1              0                  2012-10-01
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, if feel like this should be really simple and accomplished by a function
Feel like this should be something easy that I'm missing. I have a table
Okay, two alternatives, but before I begin, you need to know this: public abstract
Okay, I have done a bit of searching online and found this thread, but
Okay I almost have this rebase thing figured out. I can feel a breakthrough
Okay, I feel like I am missing something really simple here. I have an
Okay, so this should be a simple question, but I'm fairly new at programming,
Okay, I feel like a bit of a 800 pound gorilla trying to thread
Okay, I feel totally stupid posting this. I am not sure if it is
okay so this is probably a soft pitch question for sombody, but I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.