Return to Snippet

Revision: 30558
at August 17, 2010 12:37 by kwanhon


Initial Code
select from_unixtime(
       unix_timestamp('2008-01-01 01:00:00')+floor(rand()*31536000)
);

Initial URL
http://blog.underdog-projects.net/2008/10/generate-random-timestamps-in-mysql/

Initial Description
For me I wanted a value between 2008 and 2009 (one year: 60 seconds * 60 minutes * 24 hours * 365 days = 31536000). Because the Unix timestamp doesn’t support fractions your need to round the value to an int. (floor or round the value).

Initial Title
Generate Random Date in Mysql

Initial Tags

                                

Initial Language
MySQL