2010-09-04 95 views

回答

2

DateInterval類下面是一個粗略的開始:

function makeDayArray($startDate , $endDate){ 
// Just to be sure - feel free to drop these is your sure of the input 
    $startDate = strtotime($startDate); 
    $endDate = strtotime($endDate); 

// New Variables 
    $currDate = $startDate; 
    $dayArray = array(); 

// Loop until we have the Array 
    do{ 
    $dayArray[] = date('Y-m-d' , $currDate); 
    $currDate = strtotime('+1 day' , $currDate); 
    } while($currDate<=$endDate); 

// Return the Array 
    return $dayArray; 
} 
0

我發現這個線程,而我一直在尋找同樣的事情。這就是我想到的,這很好。

我有一個他們訂閱電子郵件列表的電子郵件地址和unix時間戳的數據庫。我想知道每週的訂閱費用是多少。

$startdate = 1325376000; // Jan 1 2012 
//$startdate = 1293926400; // Jan 1 2011 
$currentstart = $startdate; 
$currentend = $startdate + 604800; // 604800 = 1 week 

while($currentend < 1356998400) { 
    $sql = "SELECT * FROM the_table WHERE unixdate > $currentstart AND unixdate <= " . ($currentstart + 604800 - 1); 
    $result = mysql_query($sql); 
    echo date('D Y-m-d', ($currentstart)) . " - " . date('D Y-m-d', ($currentstart + 604800 - 1)) . ": <strong>" . mysql_num_rows($result) . "</strong><br />"; 
    $currentstart = $currentend; 
    $currentend += 604800; 
} 

您可以將604800號碼更改爲30天或365天或每天或其他的間隔。

我確定這不太好 - 我不是最好的編碼器 - 但我不得不爲我後面的人留下我的解決方案。