fork download
  1. <?php
  2.  
  3. $start = 1492894800; //23/04/2017
  4. $end = 1503521999; //23/08/2017
  5.  
  6. $steps = date('Ym', $end) - date('Ym', $start);
  7.  
  8. $timestamps = array();
  9. for($i = 0; $i <= $steps; $i++) {
  10. $base = strtotime("+{$i} months", $start);
  11.  
  12. $timestamps[] = array(
  13. 'from' => $i == 0 ? date('Y-m-d', $start) : date('Y-m-01', $base),
  14. 'to' => $i == $steps ? date('Y-m-d', $end) : date('Y-m-t', $base)
  15. );
  16.  
  17. // If we want timestamps
  18. // $timestamps[] = array(
  19. // 'from' => strtotime(date('Y-m-01', $base)),
  20. // 'to' => strtotime(date('Y-m-t', $base))
  21. // );
  22. }
  23.  
  24. print_r($timestamps);
Success #stdin #stdout 0.01s 83904KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [from] => 2017-04-22
            [to] => 2017-04-30
        )

    [1] => Array
        (
            [from] => 2017-05-01
            [to] => 2017-05-31
        )

    [2] => Array
        (
            [from] => 2017-06-01
            [to] => 2017-06-30
        )

    [3] => Array
        (
            [from] => 2017-07-01
            [to] => 2017-07-31
        )

    [4] => Array
        (
            [from] => 2017-08-01
            [to] => 2017-08-23
        )

)