因為工作會常用到利用時間當作Loop的條件, 所以分享到google到的相關的寫法

PHP

<?php

// Start date
$start_date = '2015-02-01';
// End date
$end_date = '2015-02-28';

while (strtotime($date) <= strtotime($end_date)) {
    echo "$date\n";
    $date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
}
?>

Python

import datetime

def daterange(start_date, end_date):
    for n in range(int((end_date - start_date).days)):
        yield start_date + datetime.timedelta(n)

start_date = datetime.datetime.strptime('2015-03-30', '%Y-%m-%d').date()
end_date = datetime.datetime.strptime('2015-04-06', '%Y-%m-%d').date()

for single_date in daterange(start_date, end_date):
    print single_date