我在mysql表中有很多行,日期时间的格式为:
2008-12-08 04:16:51 etc
Run Code Online (Sandbox Code Playgroud)
我想生成一个30秒到3天之间的随机时间间隔,并将它们添加到上面的时间.
a)如何在30到3天之间生成随机时间?
b)如何将此时间添加到上面的日期时间格式?
我想我需要做一个循环来取出所有信息,在php中进行数学计算,然后更新行...
有任何想法吗?
使用MySQL的rand()函数:
update [table] set [field] = now() + interval floor(rand()*(60*60*24*3)) second;
Run Code Online (Sandbox Code Playgroud)
将为您提供0秒到3天之间的当前日期时间+ .