Laravel, Faker - generate timestamp before certain time?

9.8k views Asked by At

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

2

There are 2 answers

0
Jarek Tkaczyk On BEST ANSWER

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
1
igaster On

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.