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

后端 未结 3 1675
暗喜
暗喜 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:31

    You can do almost everything with the date/time operators:

    select timestamp '2014-01-10 20:00:00' +
           random() * (timestamp '2014-01-20 20:00:00' -
                       timestamp '2014-01-10 10:00:00')
    

提交回复
热议问题