亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按給定月份獲取財政年度

按給定月份獲取財政年度

PHP
牛魔王的故事 2022-07-22 10:20:16
財政年度從 4 月 1 日開始,我們在 1 月,所以 1 月進入 2020 年,2 月和 3 月也是如此。因此,如果我現在使用 April,它應該屬于 2019 年。目前我使用了以下代碼,但它沒有按照我想要的方式工作    $month =01;   if ( $month >= 4 ) {     $year = date('Y');   }   else {    $year = date('Y')-1;   }   echo $year;因此,當我將月份設置為 1 月時,年份顯示為 2019 年,但實際上應該是 2020 年。無論如何在PHP中設置年份,所以當月份從四月開始到三月底結束,所以當我輸入一個月時,我會得到正確的年份?
查看完整描述

4 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

嘗試這樣的事情:Carbon::now()->subMonths(3)->year

這樣一月、二月和三月的日期將返回 2019 年,而四月將開始返回 2020 年。


查看完整回答
反對 回復 2022-07-22
?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

我想我設法解決了這個問題。歡迎任何意見


$month =01;

$current_month = date('m');

if ($current_month >= '01' && $current_month < '4'){


   if ($month >= '01' && $month < '04'){

      $year = date('Y');

   } 


   if ($month >= 4){

      $year = date('Y')-1;

   }


if ($current_month >= 4){

   if ($month >= 4){

      $year = date('Y');

   }


   if ($month < 4){

      $year = date('Y')+1;

   }

}


echo $year;


查看完整回答
反對 回復 2022-07-22
?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

我希望這能解決你的問題


$date=date_create("2020-05-13");


echo "<br> Month: ".date_format($date,"m");

if (date_format($date,"m") >= 4) {//On or After April (FY is current year - next year)

    $financial_year = (date_format($date,"Y")) . '-' . (date_format($date,"y")+1);

} else {//On or Before March (FY is previous year - current year)

    $financial_year = (date_format($date,"Y")-1) . '-' . date_format($date,"y");

}


echo "<br> FY ".$financial_year;


查看完整回答
反對 回復 2022-07-22
?
墨色風雨

TA貢獻1853條經驗 獲得超6個贊

類似的東西:


$now = strtotime('now');

$firstApril = strtotime('1st april');

$year = ($now < $firstApril) ? date('Y')-1 : $date('Y');

return $year;

這將比較時間戳,如果它小于今年的 4 月 1 日,那么它將獲得上一年。


查看完整回答
反對 回復 2022-07-22
  • 4 回答
  • 0 關注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號