Question : Randomizing the TIME but not DATE of a timestamp in Mysql

I have a MySQL database let's say the table is called jos_content and the timestamp is called "created" of the format: "2006-11-28 06:56:00". How do you randomize the hours and minutes and seconds without affecting the date?

Is it also possible to add a where clause so that I can randomize only the timestamps in the database of a specific day?

Answer : Randomizing the TIME but not DATE of a timestamp in Mysql

okay well

update jos_content set created = date_add(created, interval rand()*6 hour)

Will add a random amount of time between 0 and 6 hours. You can also use date_sub instead of date_add to remove time.
i would suggest using both with a where clause to adjust which rows they affect to add to the randomising.

This function may though flick the day over or under the current day so you could use this to stop the update if that would happen

update jos_content set created = date_add(created, interval rand()*6 hour) where dayofyear(date_add(created, interval rand()*6 hour)) = dayofyear(created)
Random Solutions  
 
programming4us programming4us