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

  • SEARCH
  • Home
  • 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 6061471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:56:30+00:00 2026-05-23T08:56:30+00:00

Given the following database table: StartDate DATETIME — day that the reminder period starts

  • 0

Given the following database table:

StartDate DATETIME  -- day that the reminder period starts
LastReminderDate DATETIME -- the last time the reminder triggered
DayOfMonth INT -- the day of the month to remind the user
Interval INT   -- how often in months to remind the user

How can I figure out the next reminder date based on these values? For example:

StartDate = '6/1/2011'
LastReminderDate = '6/5/2011'
DayOfMonth = 5 -- remind on the 5th of the month
Interval = 2 -- remind every other month

For this particular example, the next reminder date should be 8/5/2011 because it reminds on the 5th of the month every two months. How would I write a function to figure this out?

If LastReminderDate is NULL, then LastReminderDate should be equal to StartDate

UPDATE:

StartDate = '6/1/2011'
LastReminderDate = NULL
DayOfMonth = 5
Interval = 2

In this case, there was no last reminder date. The first time the reminder would occur would be 6/5/2011. The solutions below seem to be returning 8/5 in this case.

Here are some specific rules:

  • The Reminder should always occur on whatever DayOfMonth is. If DayOfMonth would be illegal for the given month then it should be the last day of that month. For example….if DayOfMonth is 31 and the next reminder date would fall on June 31, then it should be June 30th instead.
  • The next reminder date should always be based off of the Last Reminder Date plus the Interval. If Last Reminder Date does not match the Day of Month, then it could potentially be more than what the interval was. For example…if Last Reminder was 6/1/2011 and the interval is 2 months, but the reminder is for the 20th of the month, then the next reminder will be 8/20/2011.
  • If there is no last reminder date, then use the Start Date instead of last reminder date…but this will use the earliest date in the future. If start date was 6/1/2011 and day of month is 5, then this will be 7/5/2011 since today is 6/22/2011. If Day of Month was 25 then it would be 6/25/2011
  • 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-05-23T08:56:30+00:00Added an answer on May 23, 2026 at 8:56 am
    DECLARE
    @StartDate AS datetime,  -- day that the reminder period starts
    @LastReminderDate AS datetime, -- the last time the reminder triggered
    @DayOfMonth AS integer, -- the day of the month to remind the user
    @Interval AS integer   -- how often in months to remind the user
    
    SET @StartDate = '6/1/2011'
    SET @LastReminderDate = '6/5/2011'
    SET @DayOfMonth = 5 -- remind on the 5th of the month
    SET @Interval = 2 -- remind every other month
    
    SELECT
    CASE
       WHEN @LastReminderDate IS NULL
       THEN
         CASE WHEN Day(@StartDate) <= @DayOfMonth
           THEN DateAdd( month, ((Year( @StartDate ) - 1900) * 12) + Month( @StartDate ) - 1, @DayOfMonth - 1 )
           ELSE DateAdd( month, ((Year( @StartDate ) - 1900) * 12) + Month( @StartDate ) - 0, @DayOfMonth - 1 )
         END
      ELSE DateAdd( month, @Interval, @LastReminderDate )
    END
    

    The meat of this is the last four lines, the SELECT CASE ... END statement. I provided a whole script that lets you plug in different values, and see how the SELECT CASE ... END behaves for those test values.

    But to just use this on your table, use only the last four lines (and remove the @ from the front of the names so they match the table’s column names).

    You could also generalize this so that Interval doesn’t have to be months. If your table had an IntervalType column, you could supply that as the first argument to DateAdd(). See the docs but some common intervals are days, months, years, and so on.

    EDIT2: Respect DayOfMonth.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following tables stored in SQL database Table person id username phone 1
Given the following XML: <databases> <database> <title_display>Aardvark</title_display> </database> <database> <title_display>Apple</title_display> </database> <database> <title_display>Blue</title_display> </database>
Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>
Given the following: declare @a table ( pkid int, value int ) declare @b
Given the following code (that doesn't work): while True: # Snip: print out current
I have the following database table with information about people, diseases, and drugs: PERSON_T
I have the following database table with information about people, diseases, and drugs: PERSON_T
Given the following (heavily simplified) tables: create table Tags ( TagId int Primary Key
Consider the following database tables: Table messages with 13,000,000 rows (one row per message).
I have a database-table with the following structure: id1 | id2 | weight Now

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.