I’am very confused to get someone’s birthday date by changing Y-m-d to m-d in the date_birth field. How should I do? This is my current code:
$getBirthday = Karyawan::where('date_birth', Carbon::now()->format('m-d'))->get();
Thanks, I want to get someone’s birthday by taking m-d only from date_birth field. Hope u’re helping me!
>Solution :
You can query using the mysql DATE_FORMAT method and using whereRaw
$getBirthday = Karyawan::whereRaw("DATE_FORMAT(birthdate, '%m-%d') = ?", [Carbon::now()->format('m-d')])->get();