Categories

Saturday, December 21, 2024
#919814419350 therichposts@gmail.com
LaravelLaravl 5.7

Best Practices for Laravel Date Time Queries

Laravel 7.2 routing with route group auth guard check with prefix

Best Practices for Laravel Date Time Queries

Hello to all, welcome to therichpost.com. In this post, I am sharing the tricks for, Best Practices for Laravel Date Time Queries.

I am sharing all these because I was not aware that laravel gives us these kind of date time queries to get rid of date time custom functions and this thing, I like very much and that is why laravel makes things easy to understandable. 

I just share that code, which I do or I think, this could be important in future.

 

Here are the those wonderful Date Time Laravel Queries: 

 

1. The whereDate method may be used to compare a column’s value against a date:

$users = DB::table('users')
                ->whereDate('created_at', '2016-12-31')
                ->get();

 

2. The whereMonth method may be used to compare a column’s value against a specific month of a year:

$users = DB::table('users')
                ->whereMonth('created_at', '12')
                ->get();

 

3. The whereDay method may be used to compare a column’s value against a specific day of a month:

$users = DB::table('users')
                ->whereDay('created_at', '31')
                ->get();

 

4. The whereYear method may be used to compare a column’s value against a specific year:

$users = DB::table('users')
                ->whereYear('created_at', '2016')
                ->get();

 

5. The whereTime method may be used to compare a column’s value against a specific time:

$users = DB::table('users')
                ->whereTime('created_at', '=', '11:20:45')
                ->get();

 If have any query related this, then do comment or ask questions.

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.