首页 > 解决方案 > Laravel - 我如何查询月份和年度日期?

问题描述

我是 Laravel 的新手,不太确定该怎么做。

我在我的数据库中记录日期,就像start_day在我的times表中一样。
日期以以下格式保存:2019-10-03

现在我只有:

$months = DB::table('times')->where('start_day', '=', 2019)

我应该如何选择一年中每个月的数据?

标签: phplaraveleloquent

解决方案


您需要将 to 更改为where()whereYear()年份搜索。

$months = DB::table('times')->whereYear('start_day', '=', 2019)

推荐阅读