Kamil Gosciminski
Kamil Gosciminski

Reputation: 17147

SQL Apply random part in seconds to a timestamp

I have a field Date that is of type timestamp and as default it is set to current_timestamp.

I need it to be changed randomly (by adding random amount of seconds). Essentially, what I'm looking for is something alike:

SET Date = current_timestamp + x 

where x is provides an arbitrary integer

For example x can be one of those:

1000
Round(Rand() * 1000)

Expected result (proper timestamp) sometimes, but very rarely shows up, but almost all the time it is

00-00-0000 00:00:00

Upvotes: 0

Views: 328

Answers (1)

Rogue
Rogue

Reputation: 11483

Look into using DATE_ADD

SET `date` = DATE_ADD(`date`, INTERVAL ROUND(RAND() * 1000) SECONDS)

Upvotes: 1

Related Questions