首页 > 解决方案 > 如何在 Laravel 中获取下个月生日的结果?

问题描述

我有这个代码,但我不能只查询今天的生日。如果我需要这种查询类型该怎么办?

无论年份如何,我都需要一个生日(只有日期和月份)。


    public function birth(Request $request)
{

$today = Carbon::now()->format('Y-m-d');


  $birthday = DB::table('customers')
                     ->select('id_user','first_name','last_name','birth_date','open_user_date')
                     ->where('birth_date',$today)
                     ->get();



      return view('reports/birth',compact('birthday','date','today','hbddate'));
  }

标签: sqllaravel

解决方案


您可以使用此代码让客户今天过生日。

$today = Carbon::now()->format('m-d');

$birthday = DB::table('customers')
                         ->select('id_user','first_name','last_name','birth_date','open_user_date')
                         ->where(DB::raw(DATE_FORMAT(birthDate,'%m-%d'), $today))
                         ->get();

推荐阅读