cal_days_in_month()[function.cal-days-in-month]:日期无效

时间:2013-07-16 01:21:22

标签: php

我想计算一个月的天数。这似乎是警告:

cal_days_in_month() [function.cal-days-in-month]: invalid date. 

任何人都可以帮助我。 :

$numberofday = new DateTime($month);
$numberofday = cal_days_in_month(CAL_GREGORIAN, $month,$year1);
$Total=$length  x 24  x $numberofday ; 

3 个答案:

答案 0 :(得分:0)

cal_days_in_month()接受月份字段的整数值,请将月份转换为整数:

$month = "april";
$year1 = "2013";
$month = date('m', strtotime($month));

使用该功能之前。

$numberofday = cal_days_in_month(CAL_GREGORIAN, $month, $year1);

替代cal_days_in_month

$month = "april";
$year1 = "2013";
$numberofday = date('t', strtotime("$year1-" . date("m",strtotime($month)) . "-01"));

也:

$Total=$length  x 24  x $numberofday;

应该是:

$Total=$length * 24 * $numberofday;

答案 1 :(得分:0)

你有'长度',它应该是$ length吗?

答案 2 :(得分:0)

$ month = 4;

$ year1 = 2013;

$ numberofday = cal_days_in_month(CAL_GREGORIAN,$ month,$ year1);

echo $ numberofday; // 30