PostgreSQL获取两个日期时间/时间戳之间的随机日期时间/时间戳 [英] PostgreSQL Get a random datetime/timestamp between two datetime/timestamp
本文介绍了PostgreSQL获取两个日期时间/时间戳之间的随机日期时间/时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
标题非常明确,我的问题是我是否有两个小时的时间:
The title is pretty much explicit, my question is if i get two dates with hour:
- 2014年10月1日10: 00:00
- 2014年1月20日20:00:00
是否可能在这两个日期时间之间选择一个随机的日期时间?
Is it possible to pick a random datetime between these two datetime ?
我尝试使用random()函数,但是我真的不知道如何在日期时间中使用它
I tried with the random() function but i don't really get how to use it with datetime
谢谢
马修(Matthiew)
Matthiew
推荐答案
使用日期/时间运算符:
select timestamp '2014-01-10 20:00:00' +
random() * (timestamp '2014-01-20 20:00:00' -
timestamp '2014-01-10 10:00:00')
这篇关于PostgreSQL获取两个日期时间/时间戳之间的随机日期时间/时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文