How to query data by grouping them by date in Laravel?
up vote
0
down vote
favorite
I have an array which consist of date and time with 'x' seconds of time interval as shown below [Example 1].
I am not sure of the ways of writing a query to group the data from array[0] to array[1], array[2] to array[3].
Can anybody help me out here ? Thank you.
Example 1:
array:15 [▼
0 => "'2018-11-01 00:00:00'"
1 => "'2018-11-01 00:30:00'"
2 => "'2018-11-01 01:00:00'"
3 => "'2018-11-01 01:30:00'"
4 => "'2018-11-01 02:00:00'"
5 => "'2018-11-01 02:30:00'"
6 => "'2018-11-01 03:00:00'"
7 => "'2018-11-01 03:30:00'"
8 => "'2018-11-01 04:00:00'"
9 => "'2018-11-01 04:30:00'"
10 => "'2018-11-01 05:00:00'"
11 => "'2018-11-01 05:30:00'"
12 => "'2018-11-01 06:00:00'"
13 => "'2018-11-01 06:30:00'"
14 => "'2018-11-01 07:00:00'"
15 => "'2018-11-01 07:30:00'"
]
My current query looks like this
$testQuery = DB::Table('receipt_tbl')
// ->whereRaw('created_at IN (' . implode(',' ,$timeIntv) . ')')
->whereBetween('created_at', [ Carbon::createFromTimestamp($startDate) , Carbon::createFromTimestamp($endDate)])
->where('receipt_type', $receiptObj->id)
// ->groupBy('group_date')
->get();
php laravel datetime php-carbon
add a comment |
up vote
0
down vote
favorite
I have an array which consist of date and time with 'x' seconds of time interval as shown below [Example 1].
I am not sure of the ways of writing a query to group the data from array[0] to array[1], array[2] to array[3].
Can anybody help me out here ? Thank you.
Example 1:
array:15 [▼
0 => "'2018-11-01 00:00:00'"
1 => "'2018-11-01 00:30:00'"
2 => "'2018-11-01 01:00:00'"
3 => "'2018-11-01 01:30:00'"
4 => "'2018-11-01 02:00:00'"
5 => "'2018-11-01 02:30:00'"
6 => "'2018-11-01 03:00:00'"
7 => "'2018-11-01 03:30:00'"
8 => "'2018-11-01 04:00:00'"
9 => "'2018-11-01 04:30:00'"
10 => "'2018-11-01 05:00:00'"
11 => "'2018-11-01 05:30:00'"
12 => "'2018-11-01 06:00:00'"
13 => "'2018-11-01 06:30:00'"
14 => "'2018-11-01 07:00:00'"
15 => "'2018-11-01 07:30:00'"
]
My current query looks like this
$testQuery = DB::Table('receipt_tbl')
// ->whereRaw('created_at IN (' . implode(',' ,$timeIntv) . ')')
->whereBetween('created_at', [ Carbon::createFromTimestamp($startDate) , Carbon::createFromTimestamp($endDate)])
->where('receipt_type', $receiptObj->id)
// ->groupBy('group_date')
->get();
php laravel datetime php-carbon
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have an array which consist of date and time with 'x' seconds of time interval as shown below [Example 1].
I am not sure of the ways of writing a query to group the data from array[0] to array[1], array[2] to array[3].
Can anybody help me out here ? Thank you.
Example 1:
array:15 [▼
0 => "'2018-11-01 00:00:00'"
1 => "'2018-11-01 00:30:00'"
2 => "'2018-11-01 01:00:00'"
3 => "'2018-11-01 01:30:00'"
4 => "'2018-11-01 02:00:00'"
5 => "'2018-11-01 02:30:00'"
6 => "'2018-11-01 03:00:00'"
7 => "'2018-11-01 03:30:00'"
8 => "'2018-11-01 04:00:00'"
9 => "'2018-11-01 04:30:00'"
10 => "'2018-11-01 05:00:00'"
11 => "'2018-11-01 05:30:00'"
12 => "'2018-11-01 06:00:00'"
13 => "'2018-11-01 06:30:00'"
14 => "'2018-11-01 07:00:00'"
15 => "'2018-11-01 07:30:00'"
]
My current query looks like this
$testQuery = DB::Table('receipt_tbl')
// ->whereRaw('created_at IN (' . implode(',' ,$timeIntv) . ')')
->whereBetween('created_at', [ Carbon::createFromTimestamp($startDate) , Carbon::createFromTimestamp($endDate)])
->where('receipt_type', $receiptObj->id)
// ->groupBy('group_date')
->get();
php laravel datetime php-carbon
I have an array which consist of date and time with 'x' seconds of time interval as shown below [Example 1].
I am not sure of the ways of writing a query to group the data from array[0] to array[1], array[2] to array[3].
Can anybody help me out here ? Thank you.
Example 1:
array:15 [▼
0 => "'2018-11-01 00:00:00'"
1 => "'2018-11-01 00:30:00'"
2 => "'2018-11-01 01:00:00'"
3 => "'2018-11-01 01:30:00'"
4 => "'2018-11-01 02:00:00'"
5 => "'2018-11-01 02:30:00'"
6 => "'2018-11-01 03:00:00'"
7 => "'2018-11-01 03:30:00'"
8 => "'2018-11-01 04:00:00'"
9 => "'2018-11-01 04:30:00'"
10 => "'2018-11-01 05:00:00'"
11 => "'2018-11-01 05:30:00'"
12 => "'2018-11-01 06:00:00'"
13 => "'2018-11-01 06:30:00'"
14 => "'2018-11-01 07:00:00'"
15 => "'2018-11-01 07:30:00'"
]
My current query looks like this
$testQuery = DB::Table('receipt_tbl')
// ->whereRaw('created_at IN (' . implode(',' ,$timeIntv) . ')')
->whereBetween('created_at', [ Carbon::createFromTimestamp($startDate) , Carbon::createFromTimestamp($endDate)])
->where('receipt_type', $receiptObj->id)
// ->groupBy('group_date')
->get();
php laravel datetime php-carbon
php laravel datetime php-carbon
asked Nov 11 at 14:48
topacoBoy
80411
80411
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249855%2fhow-to-query-data-by-grouping-them-by-date-in-laravel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown