Skip to content

Instantly share code, notes, and snippets.

@medigeek
Created September 25, 2020 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save medigeek/ff5411123e1d403eeef43b10fea64abf to your computer and use it in GitHub Desktop.
Save medigeek/ff5411123e1d403eeef43b10fea64abf to your computer and use it in GitHub Desktop.
getting a time period with stepping in php (I know, I know... CarbonPeriod)
<?php
printf("<pre>\n");
$secStep = 5;
$a = strtotime("2020-09-24 07:04:35 UTC");
$b = strtotime("2020-09-24 07:05:50 UTC");
var_dump($a);
var_dump($b);
$timeDiffSec = $b - $a;
var_dump($timeDiffSec);
for ($i = $secStep; $i < $timeDiffSec; $i+=$secStep) {
$iTimeSeconds = $a + $i;
$iTimeString = strftime('%F %T %Z', $iTimeSeconds);
echo "timestep: $i total: $splitDiffSec -- $iTimeString\n";
}
printf("</pre>\n");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment