Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JackD's avatar

display new registered user on current date

i have this code to test my query to count the registered users based on the current date

sorry about my logic on code im starting to learn yet if any good suggestion please comment below i will really appreciate it as a part of my learning process

\App\User::where('created_at','>',date('Y-m-d 00:00:00'))->count()

ci

0 likes
3 replies
Kemito's avatar

@Ci as long as created_at have index (i guess) this should be fine. Without index it can start make problems on higher count of records. If your code works as you showed (looks fine for me) you should not be much worried about. Its pretty fine.

Alternative solutions for this (as long as index for created_at)

whereRaw('DATE(created_at) = 2015-04-16')
where('created_at', '>=', '2015-04-16')->where('created_at', '<', '2015-04-17');

Quick note: if you use '=' you can skip 2nd parameter. By default it will be '='

toniperic's avatar

Or if you want to leverage Carbon, as it's pulled into Laravel by default so it's a good idea to use it, then you could try this:

User::where('created_at', '>=', Carbon::now()->startOfDay())
    ->where('created_at', '<=', Carbon::now()->endOfDay());
1 like

Please or to participate in this conversation.