2010-09-04 104 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天或每天或其他的间隔。

我确定这不太好 - 我不是最好的编码器 - 但我不得不为我后面的人留下我的解决方案。