Using Carbon to Generate Random Dates and Times
There are a number of ways to generate random dates/times in PHP. Here are some examples using the Carbon library:
1 2 3 4 5 6 7 8 9 10 11 |
// Between now and 180 days ago Carbon::today()->subDays(rand(0, 180)) > 2021-09-02 00:00:00 > 2021-06-23 00:00:00 > 2021-05-23 00:00:00 // Between now and 180 days ago with random time Carbon::today()->subDays(rand(0, 179))->addSeconds(rand(0, 86400)); > 2021-06-11 22:35:03 > 2021-10-24 13:19:53 > 2021-06-09 20:47:44 |