View Single Post
  #2   IP: 112.87.30.158
Old 2015-04-19, 06:16 AM
Imlay City Imlay City is offline
初级会员
 
Join Date: 2005-12-30
Posts: 1
Imlay City 现在声名狼藉
Default

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 uses the date 2010-04-30 14:53:27 as the base, converts that to a Unix timestamp, and adds a random number of seconds from 0 to +2 years to the base date and converts it back to a DATETIME.

It should be pretty close but over longer time periods leap years and other adjustments will throw it off.
Reply With Quote