Laravelを用いてますが、Carbon
はcomposer
から入れれるので同じです。
上期は基本的に4月から9月末、下期は10月から3月末のようなので、そのように定義します。
今回はweb.php
にコールバックに書いていきます
web.php
Route::get('/',function(){
$start = today()->month(4)->firstOfMonth();
$end = today()->month(9)->endOfMonth();
});
上期の開始と終了を定義しました。
today()
はLaravelに用意されているヘルパです。
new Carbon('today')
と同等になります。
web.php
Route::get('/',function(){
$start = today()->month(4)->firstOfMonth();
$end = today()->month(9)->endOfMonth();
echo today()->between($start , $end ) ? '上' : '下');
});
あとは、今日が上期の範囲内か判断しているだけです。