![]() |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
IP: 112.87.30.158
|
|||
|
|||
|
Looking for a way to add random dates to a column in one of your MySQL tables?
I ran across this problem and found a straightforward solution. By utilizing str_to_date(), concat(), floor() and rand() you can specify a random date for a column. Code:
update mytable
set mycolumn = str_to_date(
concat(
floor(1 + rand() * (12-1)), /* Generate a random month */
'-',
floor(1 + rand() * (28 -1)), /* Generate a random day */
'-',
'2008'
),
'%m-%d-%Y'
);
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MySQL毫秒值和日期的指定格式的相互转换 | Kaitlin | MySQL | 0 | 2015-04-18 11:01 PM |
| mysql 帮助文档使用 | Haddam | MySQL | 0 | 2014-11-26 06:43 PM |
| Simple Steps to Change Your Table Prefix in WordPress | Abby | WordPress | 0 | 2014-04-14 03:40 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 |