today's date I want to capture today's date. How to do so?
$date = new DateTime();
$today = date('yy-mm-dd');
dd($today);
I put this script in the controller. I wonder why it keep bypassing the dd($today)?
What you have is fine, but you don't need $date = new DateTime(), and the correct format string would be:
date('y-m-d') // 18-10-12
// or
date('Y-m-d'); // 2018-10-12
There is a Carbon instance returned from this method which you can format as you please:
today()
Then I try to compare the date with date and time. As long as the date is the same without considering the time, then it should be counted.
$count_tgl = TrxHarianModel::select('paydate')
->where('paydate', '=', $today)
->count();
I wonder why the result is 0. I already tested by inputing the value of today:
$today = '2018-08-02';
Equality is a tough test in a standard where, I suggest whereDate instead which will cast the datetime field in the database to a date before making the comparison:
$count_tgl = TrxHarianModel::select('paydate')
->whereDate('paydate', '=', $today)
->count();
Please sign in or create an account to participate in this conversation.