[英]SQL's date function not working as expected
我正在嘗試在Laravel 4.2中使用MySQLs日期函數,但似乎無法正常工作,或者我做錯了什么...
查詢:
[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
表格的屏幕截圖: https : //i.gyazo.com/1ad25c1b536be7e5f794256cb1ced1ea.png
我想忽略時間,只知道日期。 我知道我做錯了事,但不確定。
有任何想法嗎?
您沒有在該日期創建的記錄。 在屏幕截圖中,所有記錄均在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.