Search code examples
phplaravelphp-carbon

Getting random date between two dates


Is there a way I can get a random date between two dates in Carbon? For example, I am trying to get a random date between now and 55 mins ago.

$dateNow = Carbon::now();
$date25MinsAgo = Carbon::now()->subMinutes(55);

However, I am stuck at this point. I found some info on php, but I want to use 'now' as it's a seeder. What should I do?


Solution

  • Use rand():

     $random = Carbon::now()->subMinutes(rand(1, 55));