Created
July 31, 2015 23:36
-
-
Save jeffjohnson9046/11204a5f662315aef6f0 to your computer and use it in GitHub Desktop.
MSSQL - Generate a random datetime value for a given year.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @RandomDate datetime | |
SELECT @RandomDate = | |
DATEADD(day, ROUND(DATEDIFF(day, '2015-01-01', '2015-12-31') * RAND(CHECKSUM(NEWID())), 0), | |
DATEADD(second, CHECKSUM(NEWID()) % 48000, '2015-01-01')) | |
/* Verify */ | |
SELECT RandomDate = @RandomDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Genius! Thank you