douyijin7741 2019-08-09 01:23
浏览 194

如何在MySQL查询中使用MONTHNAME来匹配月份

I'm building a query so I can get a list of new users by month:

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;

    }

An example of "account_creation_date" value is "08/08/2019 4:55 pm"

Im trying to pass in a month name like "August" and have the query convert the account_creation_date values to their month names.

Although I'm getting no errors, nothing is returning when the query is executed.

How can I accomplish this? Is MONTHNAME what I want?

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制