Laravel whereBetween
method are useful when you retrieve records in between two given dates from timestamp column.
Suppose you want to filter records in database table by from data and to date then you can use whereBetween
method to filter the records.
- if ($request->input('from_date')<>'' && $request->input('to_date')<>'')
- {
- $start = date("Y-m-d",strtotime($request->input('from_date')));
- $end = date("Y-m-d",strtotime($request->input('to_date')."+1 day"));
- $query->whereBetween('created_at',[$start,$end]);
- }
- $created_at = new Carbon($product->created_at);
- $now = Carbon::now();
- $difference = ($created_at->diff($now)->days < 1)
- ? 'today'
- : $created_at->diffForHumans($now);
- $to_date = Carbon::createFromDate('Y-m-d H:s:i', '2013-5-5 5:10:12');
- $from_date = Carbon::createFromDate('Y-m-d H:s:i', '2014-6-6 7:20:14');
- $diffInHours = $to_date->diffInHours($from_date, false);
- $diffInMinutes = $to_date->diffInMinutes($from_date, false);
- $diffInDays = $to_date->diffInDays($from_date, false);