简体   繁体   English

SQL的日期功能无法按预期工作

[英]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... 我正在尝试在Laravel 4.2中使用MySQLs日期函数,但似乎无法正常工作,或者我做错了什么...

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 表格的屏幕截图: 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. 在屏幕截图中,所有记录均在2016年创建,您的查询要求输入2015年。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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