mysql - INSERT EPOCH AND Unix TimeStamp between 2 dates -
i have small issue, have insert sql statement follows:
insert table (`col`, `col`, `col`) values '1', '2', floor(950000+rand()*(550000-950000));
one of columns epoch unix timestamp, want able randomize inserts between 2 dates: example:
randomized insert value between: 1469696000 , 1479996000
how can achieve using rand set condition must between values when converter between epoch dates?
you can give try:
insert table (`col`, `col`, `col`) values '1', '2', (floor( 1469696000 + rand( ) *(1479996000-1469696000 )))
note:
(floor( + rand( ) * b)) return random number between , a+b (inclusive)
edit:
in order random
unix timestamp between now
, end of year:
(floor( unix_timestamp() + rand( ) *(unix_timestamp((curdate() - interval dayofyear(curdate()) day) + interval 1 year) - unix_timestamp())))
so here's full query:
insert table ( `col`, `col`, `col` ) values '1', '2', ( floor( unix_timestamp() + rand() * ( unix_timestamp( ( curdate() - interval dayofyear(curdate()) day ) + interval 1 year ) - unix_timestamp() ) ) )
Comments
Post a Comment