Random epoch time in SQL
We save all dates as bigint for a couple of reason that are off topic.
In order to test some reporting I wanted to fill a date field with random dates between a specific start and end date.
update mytable set some_date_field = 1372629600 + round(random() * 2592000) + 1
In the above query, the first number 1372629600 is my first possible date.
The second number, 2592000, is the difference between my first date and last date.
This effectively gives me random dates between the first day of the month and last day ofthe month.
Written by Jaco Groenewald
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Random
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#