Posted By

kwanhon on 08/17/10


Tagged


Versions (?)

Generate Random Date in Mysql


 / Published in: MySQL
 

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

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).

  1. SELECT FROM_UNIXTIME(
  2. UNIX_TIMESTAMP('2008-01-01 01:00:00')+FLOOR(RAND()*31536000)
  3. );

Report this snippet  

You need to login to post a comment.