Skip to content

Instantly share code, notes, and snippets.

@namnv609
Created February 18, 2016 13:43
Show Gist options
  • Save namnv609/1bb0691c94294638483c to your computer and use it in GitHub Desktop.
Save namnv609/1bb0691c94294638483c to your computer and use it in GitHub Desktop.
Create datetime range with a date
<?php
$date = "2016-01-01";
$outputFormat = "d/m/Y H:i:s";
$startTime = strtotime(date($date));
$endTime = strtotime(sprintf("%s 23:59:59", $date));
$dateTimes = [];
while ($startTime < $endTime) {
$startTime += 60;
$dateTimes[] = date($outputFormat, $startTime);
}
echo "<pre>";
var_dump($dateTimes);
echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment