I\'m writing some code to populate a MySQL database with random data for testing purposes. I need to populate a DATE column with random dates from 1970-2015.
DATE
Try something like this.
public static void main(String[] args) { LocalDate start = LocalDate.of(1970, Month.JANUARY, 1); long days = ChronoUnit.DAYS.between(start, LocalDate.now()); LocalDate randomDate = start.plusDays(new Random().nextInt((int) days + 1)); System.out.println(randomDate); }