![]() |
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
#1
IP: 112.87.30.158
|
|||
|
|||
|
With SQL , Can I insert random datetime values in a column giving a range? eg. given a range of 2010-04-30 14:53:27 to 2012-04-30 14:53:27
I'm getting confused with the range part. as i will have just done this Code:
INSERT INTO `sometable` VALUES (RND (DATETIME())) |
|
#2
IP: 112.87.30.158
|
|||
|
|||
|
Here is an example that should help:
Code:
INSERT INTO `sometable` VALUES(
FROM_UNIXTIME(
UNIX_TIMESTAMP('2010-04-30 14:53:27') + FLOOR(0 + (RAND() * 63072000))
)
)
It should be pretty close but over longer time periods leap years and other adjustments will throw it off. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Random MySQL date | Kimberling City | MySQL | 1 | 2015-04-18 11:09 PM |
| MySQL毫秒值和日期的指定格式的相互转换 | Kaitlin | MySQL | 0 | 2015-04-18 11:01 PM |
| mysql 帮助文档使用 | Haddam | MySQL | 0 | 2014-11-26 06:43 PM |
| mysql安装与简单使用 | sunshine | 服务器环境搭建 | 0 | 2006-01-11 07:29 PM |
| winxp下安装全新的apache,php(5.0),mysql(5.0)... | topvip | 服务器环境搭建 | 0 | 2006-01-08 10:28 PM |