PostgreSQL Get a random datetime/timestamp between two datetime/timestamp

后端 未结 3 1698
暗喜
暗喜 2020-12-29 02:12

The title is pretty much explicit, my question is if i get two dates with hour:

  • 01-10-2014 10:00:00
  • 01-20-2014 20:00:00

Is it possible

3条回答
  •  渐次进展
    2020-12-29 02:52

    I adapted @pozs answer, since I didn't have timestamps to go off of.

    90 days is the time window you want and the 30 days is how far out to push the time window. This is helpful when running it via a job instead of at a set time.

    select NOW() + (random() * (NOW()+'90 days' - NOW())) + '30 days';
    

提交回复
热议问题