![]() |
Add Random Dates to MySQL Database
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 |
Here is a better way to do that:
Code:
UPDATE tablename SET datefield= ‘2005-01-01′ + interval rand()*883This will fill in each rows datefield with a random date between 2005-01-01 and 2006-06-02. Hope that helps! |
Here’s yet another way:
Code:
UPDATE tableNameIf you only have a DATE field, you can extract the date from the end result. For example: Code:
UPDATE tableNameGood luck! |
| All times are GMT +8. The time now is 12:26 AM. |
Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.