How to Get Current Month Records in Laravel?

How to Get Current Month Records in Laravel?

In this post we will give you information about How to Get Current Month Records in Laravel?. Hear we will give you detail about How to Get Current Month Records in Laravel?And how to use it also give you demo for it if it is necessary.

In this post, i give you example query of how to fetch current month records from table using Laravel query builder. We sometimes require to get records that created on current month.

i.e if current month is august and we need display records of august month on out admin dashboard. In this example you can see how can get you current month records and i used whereRaw() of laravel query builder with MONTH() mysql that way we can get month and compare with current month.

I have one created items table that structure as bellow you can see.

items table

Laravel Query

$currentMonth = date('m');

$data = DB::table("items")

->whereRaw('MONTH(created_at) = ?',[$currentMonth])

->get();

print_r($data);

Output:

Also see:Laravel 5 and Vue JS CRUD with Pagination example and demo from scratch

Array

(

[0] => stdClass Object

(

[id] => 4

[title] => Laravel Excel Upload

[description] => Description

[created_at] => 2016-08-07 00:00:00

[updated_at] => 2016-07-25 15:15:36

[min_quantity] => 0

)

[1] => stdClass Object

(

[id] => 5

[title] => Laravel Custom Helper

[description] => Description

[created_at] => 2016-08-07 00:00:00

[updated_at] =>

[min_quantity] => 0

)

[2] => stdClass Object

(

[id] => 6

[title] => Laravel CRUD

[description] => sdsdsdsd

[created_at] => 2016-08-07 00:00:00

[updated_at] =>

[min_quantity] => 0

)

[3] => stdClass Object

(

[id] => 7

[title] => Laravel Angularjs CRUD

[description] => Description

[created_at] => 2016-08-07 00:00:00

[updated_at] =>

[min_quantity] => 0

)

)

Hope this code and post will helped you for implement How to Get Current Month Records in Laravel?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  10  =  12

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US