剩余税年的百分比

时间:2011-09-09 13:22:49

标签: php excel date datetime

我设法使用以下内容在excel上执行此操作(请注意,我使用的是dd / mm / yyyy日期格式:)

用户输入分配给单元格A1 01/01/2007

的日期

计算以查找当前纳税年度=IF(MONTH(A1)<>4,YEAR(A1)-1,IF(DAY(A1)>=6,YEAR(A1),YEAR(A1)-1))结果是当前纳税年度为年2006

该日期的纳税年度开始= =DATE(A1,4,6)

06/04/2006结果

纳税年度结束前一天= =DATE(R54+1,4,5)

05/04/2007结果

最多天数=ABS((R55-R56))+1结果= 365(用于检测闰年)

纳税年度=ABS(R53-R55-R57)结果中传递的天数= 95

计算出纳税年度的百分比=(R58/R57)*100结果为26.02739726

现在我需要在PHP中做同样的事情,老实说不知道从哪里开始。

1 个答案:

答案 0 :(得分:0)

我会使用PHP的DateTime classDateTime::diff method

<?php
$tz = new DateTimeZone("UTC"); // Set to one of the supported time zones: http://www.php.net/manual/en/timezones.php
$tax_year_begin_dt = new DateTime("2006-04-06", $tz);
$tax_year_end_dt = new DateTime("2007-04-06", $tz);
$num_days_in_tax_year = $tax_year_begin_dt->diff($tax_year_end_dt)->days;
echo "\$num_days_in_tax_year = $num_days_in_tax_year<br>\n";
$dt = new DateTime("2007-01-01", $tz);
$num_days_remaining = $dt->diff($tax_year_end_dt)->days;
echo "\$num_days_remaining = $num_days_remaining<br>\n";
$percent_remaining = 100.0*$num_days_remaining/$num_days_in_tax_year;
echo "$percent_remaining%<br>\n";

此代码的输出为:

$num_days_in_tax_year = 365
$num_days_remaining = 95
26.027397260274%

http://codepad.viper-7.com/WNxRHS

相关问题