Skip to content

Instantly share code, notes, and snippets.

@tuto1902
Created August 8, 2023 04:52
Show Gist options
  • Select an option

  • Save tuto1902/202554b16a03009eb2324b603112d8f6 to your computer and use it in GitHub Desktop.

Select an option

Save tuto1902/202554b16a03009eb2324b603112d8f6 to your computer and use it in GitHub Desktop.

Revisions

  1. tuto1902 created this gist Aug 8, 2023.
    14 changes: 14 additions & 0 deletions carbon_time_range.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    Create an interval collection of times between 8:00 am and 5:00 pm in 30 minute intervals
    ```PHP
    $timeStep = 30
    $start = '08:00:00'
    $end = '17:00:00'
    $intervals = CarbonInterval::minutes($timeStep)->toPeriod($start, $end);
    ```

    Use the interval collection
    ```PHP
    foreach ($intervals as $date) {
    dump($date->format('H:i'))
    }
    ```