I have a timestamp column in my MySQL table.
I’m wanting to set this timestamp to a random time within the past 24 hours for all rows in the table.
I know I can update all the rows doing this:
UPDATE table SET timestamp =
But I can’t find if there’s a way to set a random timestamp that’s occurred within the past 24 hours so that each row has a different time.
Advertisement
Answer
You can use:
UPDATE table SET timestamp = now() - interval floor((24*60*60)*rand()) second;