简体   繁体   中英

SQL's date function not working as expected

I'm trying to use MySQLs date function in Laravel 4.2 but it doesn't seem to be working, or I'm doing something wrong...

Query:

[query] => select * from `activity_logs` where `user_id` = ? and date(`created_at`) = ? order by `created_at` asc

[bindings] => Array
    (
        [0] => 62731
        [1] => 2015-05-12
    )

[time] => 0.62

Screenshot of table: https://i.gyazo.com/1ad25c1b536be7e5f794256cb1ced1ea.png

I want to ignore the time, and just get the date. I know I'm doing something wrong but not sure what.

Any ideas?

You do not have records created on that date. From the screenshot all records are created 2016 and your query is asking for 2015.

如果您没有得到预期的结果,请尝试此操作,可能对您有所帮助;)

select * from `activity_logs` where `user_id` = ? and date_format(`created_at`, '%Y-%m-%d') = ? order by `created_at`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM