Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在m个月内获得n个订单的精确平均数?_Php_Date_Datetime_Datepicker - Fatal编程技术网

Php 如何在m个月内获得n个订单的精确平均数?

Php 如何在m个月内获得n个订单的精确平均数?,php,date,datetime,datepicker,Php,Date,Datetime,Datepicker,例如: $difference = strtotime($to) - strtotime($from); $months = ($difference / 86400 / 30 ); 问题:但这样我永远不会得到准确的平均值。因为我不能确定30天内也可以有31天和28天 即使我试着除以12个月的平均值,但这也不能适用于每个月的选择案例 先读,然后读 根据您自己的变化您可以使用此功能获取特定年份中特定月份的天数: 例如,您可以使用以下解决方案获得全年的天数: 此外,如果您只想获取当月的天数,可

例如:

$difference = strtotime($to) - strtotime($from);
$months = ($difference / 86400 / 30 );
问题:但这样我永远不会得到准确的平均值。因为我不能确定30天内也可以有31天和28天

即使我试着除以12个月的平均值,但这也不能适用于每个月的选择案例 先读,然后读
根据您自己的变化

您可以使用此功能获取特定年份中特定月份的天数:


例如,您可以使用以下解决方案获得全年的天数:

此外,如果您只想获取当月的天数,可以使用以下方法:

date("t");

您是否在日期范围内的月数之后?如果是这样,您可以修改前面的答案来处理您想要的:

对于我认为你想要的,你会这样做

$date_from = strtotime("2013-08-01");
$date_to = strtotime("2013-10-01");

$month_count = 0;
while ($date_from < $date_to) {
  $date_from = strtotime('+1 month', $date_from);
  $month_count++;
}

// month_count = number of months covered in the date range
从你的问题不完全确定你在追求什么

$date_from = strtotime("2013-08-01");
$date_to = strtotime("2013-08-28");
$diff = $date_to - $date_from;
$days_in_range = floor($diff / (60*60*24));

//days_in_range = 27