Use this to generate smalldatetime between January 01, 1900 and June 06, 2079 (not verified, SQL not installed)
DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0)
NEWID is better than trying to use RAND: RAND does not generate a row with different values ββin the same SELECT or UPDATE (well, this did not happen in SQL 2000, if the behavior changed).
Edit: e.g.
UPDATE table SET datetimecol = DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0)
Edit: changed from 65535 to 65530 and added ABS to avoid overflow at the upper limit of the range
gbn Apr 27 '09 at 18:25 2009-04-27 18:25
source share