1

I want to selecting and showing data based on current date. I have made query selected for this, but it not working

this is my date data on table :

a busy cat

this is my query:

$now = date('Y-m-d');
$trans = FA_transaction::where('assign_date', $now)->get();

when i execute the query, i don't get any data

3
  • what is the assign_date attribute date type? DateTime Commented Feb 18, 2019 at 6:48
  • @HaiderAli yes, it using Datetime Commented Feb 18, 2019 at 6:49
  • Possible duplicate of Laravel Eloquent compare date from datetime field Commented Feb 18, 2019 at 6:53

3 Answers 3

2

You can do :

$trans = FA_transaction::whereDate('date', Carbon::today())->get();

OR if you want to use MySQL's CURDATE function, you can do :

$trans = FA_transaction::->whereRaw('Date(date) = CURDATE()')->get();
Sign up to request clarification or add additional context in comments.

3 Comments

hello @MihirBhende, when i add where('worker_id', $getWorker->id) like this $trans = FA_transaction::where('worker_id', $getWorker->id) ->whereDate('assign_date', Carbon::today()) ->get(); I don't get any data also
Does it contain any data for the particular selection. Also do you have timezones in your system?
thanks @MihirBhende, i found my mistake, and it working now
1

You can use whereDate function to filter out records based on date try this!

$now = date('Y-m-d');
$trans = FA_transaction:: whereDate('date','=',$now)->get();

Comments

1

You can use it

 $now = Carbon::today();
 $trans = FA_transaction::where('assign_date', $now)->get();

OR

 $now = Carbon::now()->format('Y-m-d');
 $trans = FA_transaction::where('assign_date', $now)->get();

3 Comments

hello, i have tried your code and work. and i have another select data with different query like this $trans = FA_transaction::where('worker_id', $getWorker->id) ->whereDate('assign_date', Carbon::today()) ->get(); when i execute it, i don't got any data also
is it showing any error or empty?if it showing empty then check your input 1st
please share the full table

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.