Event::where('created_at','>',Carbon::parse($request->start_date))
->where('created_at','',Carbon::parse($request->end_date))
//兩個where限制開始結(jié)束時間
->groupBy('date')
->get([DB::raw('DATE(created_at) as date'),DB::raw('COUNT(*) as value')])
->toArray();
Event::where('created_at','>',Carbon::parse('2017-01-01'))
->where('created_at','',Carbon::parse('2017-11-09'))
->groupBy('day')
->get([
//通過date_format()來格式化created_at字段
DB::raw('DATE_FORMAT(created_at,\'%H') as day'),
DB::raw('COUNT(*) as value')])
->toArray()
$(function () {
/*設(shè)置開始結(jié)束時間*/
var start = moment().subtract(30, 'days');
var end = moment().subtract(-1,'day');
var datas = {};
/*選擇之后,將時間重新賦值input*/
function cb(start, end) {
$('#reportrange span').html(start.format('YYYY/MM/DD') + ' - ' + end.format('YYYY/MM/DD'));
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
/*本地化數(shù)據(jù)*/
locale: {
"format": "YYYY/MM/DD",
"separator": " - ",
"applyLabel": "應用",
"cancelLabel": "關(guān)閉",
"fromLabel": "From",
"toLabel": "至",
"customRangeLabel": "自定義",
"weekLabel": "W",
"daysOfWeek": ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"
],
"monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"
],
"firstDay": 1
},
ranges: {
'今天': [moment(), moment().subtract(-1, 'days')],
'昨天': [moment().subtract(1, 'days'), moment()],
'前7天': [moment().subtract(7, 'days'), moment()],
'前30天': [moment().subtract(30, 'days'), moment()],
'本月': [moment().startOf('month'), moment().endOf('month').subtract(-1,'day')],
'上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month').subtract(-1,'day')],
'所有': [moment("2017-09-25"), moment().subtract(-1, 'days')]
}
}, cb);
cb(start, end);
});