Generate next three month anniversary date
NickName:Simon Ask DateTime:2015-03-30T19:44:22

Generate next three month anniversary date

I have a table that contains details on charitable donations and the date they were added to the database.

I am trying to write a query that will display the next date after today that will be a three month anniversary of the record being added to the database.

Given a date in the past, I want my query to return the next date in the future that is a multiple of 3 months from the original date i.e. the three month anniversary.

See below for some examples of expected output given todays date.

Date         | Expected output
1st Feb 2015 | 1st May 2015, 
1st Sep 2014 | 1st Jun 2015

Copyright Notice:Content Author:「Simon」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29345378/generate-next-three-month-anniversary-date

Answers
Daniel E. 2015-03-30T12:15:59

Create a function that returns your looped date, then call it from your table values. There is probably a fancier/faster way to do it, but this would get you what you need.\n\nCREATE FUNCTION [dbo].[fn_Get3MonthAnniv] (@DateVal DATETIME)\nRETURNS DATETIME\nAS\nBEGIN\n DECLARE @LoopDate DATETIME = @DateVal\n DECLARE @Today as datetime = CONVERT(Date,GETDATE())\n\n While @loopDate<@today\n BEGIN\n SET @loopDate=DATEADD(Month,3,@loopDate)\n END\n\n\n RETURN @loopDate\n\nEND\nGO\n\n CREATE TABLE #dates (DateVal DATETIME)\n\nINSERT #dates (DateVal)\nVALUES ('1/1/2014')\n ,('1/1/2015')\n\nSELECT DateVal\n ,[dbo].[fn_Get3MonthAnniv](DateVal)\nFROM #dates\n\nDROP TABLE #dates\n",


More about “Generate next three month anniversary date” related questions

Generate next three month anniversary date

I have a table that contains details on charitable donations and the date they were added to the database. I am trying to write a query that will display the next date after today that will be a t...

Show Detail

Display employee anniversary dates within the next month or year of current date

basically trying to create a query that will display employee anniversary dates for upcoming month or year of current date, also would like to display a column that shows the years of service SELECT

Show Detail

First Year Anniversary Next Month

I am trying to make a SQl comand without success: WITH `params` AS ( SELECT DATEADD(MONTH, 1, CURRENT_TIMESTAMP) AS `nextmonth` ) SELECT COUNT(*) FROM `params` CROSS JOIN `Subscribers` WHERE MONTH(`

Show Detail

Calculate the next anniversary date after today

What's the quickest/neatest way to calculate the next anniversary of someone's birthday. For example, if I knew a person was born on 31st January, 1990, and today is the 10th February 2000, their ...

Show Detail

Vacation Calculation based on Anniversary Date

The rule is after you first year of employment, based on your anniversary date, you get 40 hours. (ex. I was hired on 05/12/2011, I get 40 hours vacation on 05/12/2012.) Then each subsequent year...

Show Detail

Calculating next 3 year anniversary of employee based on join date

I have an Employee mysql db table with employee name and start date. I want to be able to calculate upcoming 3 year anniversary of each employee from today's date. (So for example, Jordan's next up...

Show Detail

Excel date increments next month based on another date

I have an overly complicated spreadsheet to show when employees have taken leave from dates in a table. It behaves differently based on if today is before or after their anniversary date. There are...

Show Detail

EDATE comparable in SQL Server? -- Next Anniversary Date Calculation

Can someone help me figure out a formula to be used in SQL Server similar to the Excel formula pasted below? =EDATE(date,(DATEDIF(date,TODAY(),"y")+1)*12) I want to capture the next anniversary d...

Show Detail

How to calculate next monthly day anniversary

If I have a process I would like to run on a specific day of the month. What is the best way to calculate that anniversary each month? For example, if I want to charge someone on the 30th of each m...

Show Detail

Generate timestamp for certain date next month

I need to generate a timestamp for an exact date in the next month. I want to generate the timestamp for the 10th of the next month automatically. I tried playing around with strtotime but couldn't

Show Detail