dougeqiang1619 2012-04-27 08:12
浏览 24
已采纳

计算一周中两天之间的日期

I need an algorithm that calculates dates that are between two days of the week! for example i have

start date: 23-04-2012 and end date: 27-04-2012

now i want receive an array with this structure:

$arr = array(
  '23-04-2012',
  '24-04-2012',
  '25-04-2012',
  '26-04-2012', 
  '27-04-2012', 
  '28-04-2012'
);

thanks!

  • 写回答

3条回答 默认 最新

  • dongmozhui3805 2012-04-27 08:46
    关注
    $start = '23-04-2012';
    $end   = '27-04-2012';
    
    $startTs = strtotime("$start 00:00:00");
    $endTs   = strtotime("$end 00:00:00");
    
    $days = array();
    $day  = $startTs;
    
    $i = 0;
    
    while ($day <= $endTs) {
        $days[] = date('d-m-Y', $day);
        $i++;
        $day = mktime(0, 0, 0, date('n', $startTs), date('j', $startTs) + $i, date('Y', $startTs));
    }
    
    var_dump($days);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?