SQL Add Random Number of Days to a Date

DECLARE @MinValue INT, @MaxValue INT, @StartDateTime SMALLDATETIME SET @MinValue = 1 SET @MaxValue = 360 SET @StartDateTime = CONVERT(Varchar(10), GETDATE(), 120) -- 2011-03-01 00:00:00

Method 1

SELECT @StartDateTime AS CurrentDate, DATEADD(DAY, ROUND(((@MaxValue - @MinValue -1) * RAND() + @MinValue), 0), @StartDateTime) AS RandomFutureDate

Leave a Reply

Your email address will not be published. Required fields are marked *