Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel, Faker - generate timestamp before certain time?

Is there a way to generate time between, let's say, 00:00:00 and 15:00:00 in Faker? I tried this:

$time   = $faker->time( 'H:i:s', '15:00:00' );

but it doesn't seem to work. I keep getting values between 00:00:00 and 23:59:59

like image 498
Томица Кораћ Avatar asked Oct 27 '25 10:10

Томица Кораћ


2 Answers

This is possible with Faker now:

$faker->dateTimeBetween($startDate, $endDate);

$startDate and $endDate can be string or Carbon instances

Check the date_time provider reference for all available options.

like image 82
igaster Avatar answered Oct 28 '25 23:10

igaster


No, there is no way in Faker to achieve limit on the time part.

But forget faker for this little task:

 date('H:i:s', rand(1,54000)); // 00:00:00 - 15:00:00
like image 20
Jarek Tkaczyk Avatar answered Oct 28 '25 23:10

Jarek Tkaczyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!