sql 在MySQL中的两个日期之间生成随机日期
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 在MySQL中的两个日期之间生成随机日期相关的知识,希望对你有一定的参考价值。
Generically, FLOOR(RAND() * (<max> - <min> + 1)) + <min>
generates a number between <min> and <max> inclusive.
-- Between 17 and 44
select floor(rand() * (44 - 17 + 1)) + 17;
select
concat(
'0', floor(rand() * (79 - 70 + 1)) + 70, '/',
floor(rand() * 401) + 100, '-',
floor(rand() * 401) + 100
)
;
select date_format(
from_unixtime(
rand() *
(unix_timestamp('1967-11-13 16:00:00') - unix_timestamp('1990-11-13 23:00:00')) +
unix_timestamp('1990-11-13 23:00:00')
), '%Y-%m-%d %H:%i:%s') as datum_roden
;
select
concat(round(rand() * 10000),
round(rand() * 10000),
round(rand() * 10000),
round(rand() * 10000)
) as rnd
;
以上是关于sql 在MySQL中的两个日期之间生成随机日期的主要内容,如果未能解决你的问题,请参考以下文章