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

Abdullah_Iftikhar's avatar

how to get the data from DB by date.

I have a problem I want to get the data from data base with the selected date of user......

and i have found just month and year from user side....

so like user enter the date like "4-2019" 4 is month and 2019 is year.

so how i can get the data from database using where()............ and map on column created_at

if you have any confusion to understand the question then i m here.

Thanks

0 likes
2 replies
Abdullah_Iftikhar's avatar
Level 1

Thanks for all... I have done on my end..

    $deposit = Deposit::where('user_id' , Auth::user()->id)->whereMonth('created_at' , $date[0])
        ->whereYear('created_at' , $date[1])->orderBy('created_at' , 'desc')->get();
Nakov's avatar

I would create a Carbon object from the input, then will use whereMonth and whereYear on it, something like this:

$date = Carbon::createFromFormat('m-Y', request('date'));

User::whereMonth('created_at', $date->month)->whereYear('created_at', $date->year)->get();

let me know if it works :)

Please or to participate in this conversation.