Skip to content

Instantly share code, notes, and snippets.

@Seiger
Last active July 14, 2025 13:34
Show Gist options
  • Save Seiger/26a3584d59793db344bb0644eb1be103 to your computer and use it in GitHub Desktop.
Save Seiger/26a3584d59793db344bb0644eb1be103 to your computer and use it in GitHub Desktop.
Смаколики дя дат

Згенерувати період дат з кроком в 1 годину

Використовуємо пакет Carbon.

<?php use Carbon\CarbonPeriod;

$period = CarbonPeriod::create('2018-01-01 00:00:00', '2020-12-31 23:59:59');
$dates = [];
foreach ($period as $date) {
    $current = $date->copy();
    while ($current <= $date->copy()->endOfDay()) {
        $dates[] = $current->format('Y-m-d H:i:s');
        $current->addHour();
    }
}

dd($dates);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment