php Laravel 简单月份选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25173471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Simple Month Selection
提问by Alejandro Beltran
y tried retrieve month from date field "fechas" (datetime type) where testing with SQL clause MONTH not works... thanks for replies
您尝试从日期字段“fechas”(日期时间类型)中检索月份,其中使用 SQL 子句 MONTH 进行测试不起作用...感谢回复
$data = DB::table("ordenes")
->select(array('*', DB::raw('((cant_ped)*(precio_unit)) as sum_pedidos'), DB::raw('((cant_pend)*(precio_unit)) as sum_pends'), DB::raw('((cant_rec)*(precio_unit)) as sum_recibidos'), DB::raw('(((cant_pend)*(precio_unit)) + ((cant_rec)*(precio_unit))) as sum_importe')))
->where('cod_prov', '<>', 0)
///////////// line ERROR
->where('MONTH(fecha)', '=', '06')
///////->where('MONTH(fecha)', '=', '2014-06-20') ///test OK
->groupBy('cod_prov')
->skip(Input::get("jtStartIndex"))
->take(Input::get("jtPageSize"))
->get();
回答by Kim Tranjan
You could use the hide gem whereMonth
:
您可以使用隐藏宝石whereMonth
:
DB::table("ordenes")
->whereMonth('fecha', '=', '06')
->get();
I highly recommend to you read the Builder.php source to search for another gems. :) https://github.com/laravel/framework/blob/4.2/src/Illuminate/Database/Query/Builder.php
我强烈建议您阅读 Builder.php 源代码以搜索其他 gem。:) https://github.com/laravel/framework/blob/4.2/src/Illuminate/Database/Query/Builder.php
回答by Razor
You may try whereRaw
method
你可以试试whereRaw
方法
$data = DB::table("ordenes")
// ...
->whereRaw('MONTH(fecha) = ?', [06])
// ...
->get();
回答by Bariq Dharmawan
You could use something like this
你可以使用这样的东西
$users = Model::whereMonth('created_at', '12')->get();