网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   MySQL (https://www.0058.net/forumdisplay.php?f=76)
-   -   Generate Random Date in Mysql (https://www.0058.net/showthread.php?t=5096)

Ingleside 2015-04-19 06:38 AM

Generate Random Date in Mysql
 
For me I wanted a value between 2008 and 2009 (one year: 60 seconds * 60 minutes * 24 hours * 365 days = 31536000). Because the Unix timestamp doesn’t support fractions your need to round the value to an int. (floor or round the value).


Code:



SELECT FROM_UNIXTIME( UNIX_TIMESTAMP('2008-01-01 01:00:00')+FLOOR(RAND()*31536000)



All times are GMT +8. The time now is 01:47 AM.

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