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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -