4 回答

TA貢獻1943條經驗 獲得超7個贊
嘗試這樣的事情:Carbon::now()->subMonths(3)->year
這樣一月、二月和三月的日期將返回 2019 年,而四月將開始返回 2020 年。

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;

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;

TA貢獻1853條經驗 獲得超6個贊
類似的東西:
$now = strtotime('now');
$firstApril = strtotime('1st april');
$year = ($now < $firstApril) ? date('Y')-1 : $date('Y');
return $year;
這將比較時間戳,如果它小于今年的 4 月 1 日,那么它將獲得上一年。
- 4 回答
- 0 關注
- 132 瀏覽
添加回答
舉報