网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 服务器与数据库 > MySQL
User Name
Password
 
FAQ Members List Calendar Cheap Glasses Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1   IP: 112.87.30.158
Old 2015-04-18, 11:02 PM
Kensington Kensington is offline
初级会员
 
Join Date: 2010-04-30
Posts: 1
Kensington 现在声名狼藉
Default MySQL Generate Random Date

For testing, it can be nice to generate random date fields in sql. Because this version uses UNIX_TIMESTAMP it is limited to the range 1970 to 2038.

Code:
-- This will generate a random date between now and 2003
SELECT FROM_UNIXTIME(RAND() * (UNIX_TIMESTAMP() - UNIX_TIMESTAMP('2003-01-01')) + UNIX_TIMESTAMP('2003-01-01'));
 
UPDATE mytable 
  SET datefield = 
    FROM_UNIXTIME(RAND() * (UNIX_TIMESTAMP() - UNIX_TIMESTAMP('2003-01-01')) + UNIX_TIMESTAMP('2003-01-01'))
  WHERE 1
  AND somevalue=someothervalue;
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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
how to generate random time, pls? topvip PHP 0 2013-05-09 12:01 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

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 10:41 PM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.