Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



MySQL: Fill field w...
 
Share:
Notifications
Clear all

[Solved] MySQL: Fill field with random dates (quick and dirty)

1 Posts
1 Users
0 Reactions
1,683 Views
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter  

I had to fill a tablefield with some quick random dates for testing purposes and ran into this little gem:
(it fills the field for each record with a random date between January 1 and June 28 2013)

(source)

update project_management
set prj_first_activated = str_to_date(
concat(
floor(1 + rand() * (6 - 1)), /* Generate a random month */
'-',
floor(1 + rand() * (28 -1)), /* Generate a random day */
'-',
'2013'
),
'%m-%d-%Y'
);

Hope somebody has a use for it as well ... 


   
ReplyQuote
Share: