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 Pwm双极模式H桥驱动控制电机
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题