剩余纳税年度的百分比

发布于 2024-12-04 01:58:28 字数 639 浏览 0 评论 0原文

我设法使用以下命令在 Excel 上执行此操作(请注意,我使用 dd/mm/yyyy 日期格式:)

用户输入分配给单元格 A101/01/2007 的日期

计算以找出当前纳税年度=IF(月(A1)>>4,年(A1)-1,IF(日(A1)>=6,年(A1),年(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 中做同样的事情,老实说不知道从哪里开始。

I managed to do this on excel by using the following (note that I use the dd/mm/yyyy date format:)

User inputs Date assigned to cell A101/01/2007

Calculation to find out current tax year =IF(MONTH(A1)<>4,YEAR(A1)-1,IF(DAY(A1)>=6,YEAR(A1),YEAR(A1)-1)) Result is the current tax year is year 2006

That Date's Tax year begins = =DATE(A1,4,6) result of 06/04/2006

Day before the Tax year ends = =DATE(R54+1,4,5) result of 05/04/2007

Max number of days =ABS((R55-R56))+1 result = 365 (used to detect leap years)

Number of days passed in the tax year =ABS(R53-R55-R57) result = 95

Works out percentage of tax year left =(R58/R57)*100 result is 26.02739726

Now i need to do the same in PHP, and honestly have no idea where to start.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凶凌 2024-12-11 01:58:28

我会使用 PHP 的 DateTimeDateTime::diff 方法

<?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

I would use PHP's DateTime class and the DateTime::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";

The output of this code is:

$num_days_in_tax_year = 365
$num_days_remaining = 95
26.027397260274%

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文