MySQL rand unix timestamp without additional PHP loop + subquery

December 18, 2012    Mysql Development mysql rand

Figured we could improve a PHP script to not require an additional loop around records and sub query today.

This query will insert a random unix timestamp between now and 86399 seconds time (or almost one day) for each row.

I've found it to be an improvement on sub queries.

UPDATE dummy_table SET time_field = UNIX_TIMESTAMP(NOW())+FLOOR(1 + (RAND() * 86399));

blog comments powered by Disqus