--- tags: PHP, Laravel, Backend disqus: HackMD --- # Laravel 查找月份,年份,日期資料 ## 查找日期whereDate() 查找'2022-02-10'日期 ```php= Post::whereDate('created_at', '2022-02-10')->get(); ``` 查找今天日期資料 ```php= Post::whereDate('created_at', Carbon::now->toDateString())->get(); ``` ## 查找年份whereYear() 查找'2022'年資料 ```php= Post::whereYear('created_at', '2022')->get(); ``` 查找今年資料 ```php= Post::whereYear('created_at', Carbon::now->format('Y'))->get(); ``` ## 查找月份whereMonth() 查找'2'月資料 ```php= Post::whereMonth('created_at', '2022')->get(); ``` 查找當月資料 ```php= Post::whereMonth('created_at', Carbon::now->format('m'))->get(); ``` ## 查找日whereDay() 查找'10'號資料 ```php= Post::whereDay('created_at', '10')->get(); ``` 查找當月資料 ```php= Post::whereDay('created_at', Carbon::now->format('d'))->get(); ```