Skip to content

Instantly share code, notes, and snippets.

@tuto1902
Created August 8, 2023 04:52
Show Gist options
  • Save tuto1902/202554b16a03009eb2324b603112d8f6 to your computer and use it in GitHub Desktop.
Save tuto1902/202554b16a03009eb2324b603112d8f6 to your computer and use it in GitHub Desktop.
Generate time range with Carbon

Create an interval collection of times between 8:00 am and 5:00 pm in 30 minute intervals

$timeStep = 30
$start = '08:00:00'
$end = '17:00:00'
$intervals = CarbonInterval::minutes($timeStep)->toPeriod($start, $end);

Use the interval collection

foreach ($intervals as $date) {
    dump($date->format('H:i'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment