Laravel Eloquent whereTime Query Example

Laravel Eloquent whereTime Query Example

Laravel provides numerous eloquent methods, and you can use different eloquent methods for a different purposes.

But In this laravel tutorial, you will learn about whereTime eloquent method. As well as how to use this eloquent method with laravel query builder and model.

When you develop any application in laravel, and you want to fetch records of specific time only. At that time, you can use laravel whereTime() eloquent method with query.

Here you will see many examples of laravel whereTime method:

Example 1: whereTime method with query builder

$users = DB::table('users')
             ->whereTime('created_at', '=', '09:50:11')
             ->get();
dd($users);

Example 2: whereTime method with eloquent model

$users = User::whereTime('created_at', '=', '09:50:11')
             ->get();
dd($users);

The whereTime query will compare a column’s value against a given specific time in this. And the get result accordingly.

When you dump the above given whereTime query you will get the following SQL query:

select * from `users` where time(`created_at1`) = 09:50:11

And you can also write this whereTime query without operator as follow:

$users = User::whereTime('created_at1', '09:50:11')->get();
dd($users);

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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