Laravel Eloquent Birthdays Query to get Date Column based on Date and Month only -
i have date() column in mysql has date of birth in mysql’s yyyy-mm-dd format:
$table->date('dob')->nullable(); i trying query table lists users having birthdays today till next 7 days. have right now:
$date = new carbon; $today = $date->format('y-m-d'); $futuredays = $date->adddays(7)->format('y-m-d'); $birthdays = siteusers::where('dob', '>=', $today) ->where('dob', '<=', $futuredays) ->orderby('dob', 'asc') ->get(); the problem above query lists users having dob exact dates in year not right. want list users having birthdays irrespective of year born matching ‘date’ , ‘month’ , ignoring ‘year’.
i don’t know how achieve that. can me out please…
shortly after posted question, tried method using raw queries uses dateofyear() sql function. have seems working getting users birthdays in next 7 days irrespective of year:
$birthdays = siteusers::->whereraw('dayofyear(curdate()) <= dayofyear(dob) , dayofyear(curdate()) + 7 >= dayofyear(dob)') ->orderbyraw('dayofyear(dob)') ->get();
Comments
Post a Comment