php - 如何在 MySQL 查询中使用 MONTHNAME 来匹配月份
问题描述
我正在构建一个查询,以便按月获取新用户列表:
public function getNewUsers($month) {
$month = date('F', strtotime($month));
$sql = "SELECT * FROM `{$this->table}` WHERE MONTHNAME(`account_creation_date`) = {$month} ORDER BY `id` DESC";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([$month]);
if ($stmt->rowCount() == 0) return null;
$users = $stmt->fetchAll(PDO::FETCH_NAMED);
foreach ($users as &$user) {
$user = $this->applyRelations($user);
}
return $users;
}
“account_creation_date”值的示例是“08/08/2019 4:55 pm”
我试图传递一个像“August”这样的月份名称,并让查询将 account_creation_date 值转换为它们的月份名称。
尽管我没有收到任何错误,但执行查询时没有返回任何内容。
我怎样才能做到这一点?MONTHNAME 是我想要的吗?
谢谢!
解决方案
推荐阅读
- python - 如何检查 objedc 是否具有属性 false o true
- python-3.x - 比较两个文件的每个元素(逐行)
- html - 相对于显示的内容而不是页面定位播放按钮
- pandas - 我想替换异常值而不是完全删除它...有什么建议吗?
- amazon-web-services - 每天将大量 csv 数据摄取到弹性搜索中
- reactjs - 如何在材料 ui datepicker 中仅获取日期?
- asp.net - 如何在 ASP.NET 中显示时间?
- jquery - 使用 Jquery - 在两个给定类之间查找特定类并添加内容
- c - 为什么 > 运算符不能正常工作?
- ios - 使用按钮切换视图根本不起作用