sql - 如何在 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'));
}
解决方案
您可以使用此代码让客户今天过生日。
$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();
推荐阅读
- c++ - 当我尝试包含头文件时,为什么会出现错误“没有这样的文件或目录”?
- python - 用 on 循环替换 Python 列表中的特定字符
- javascript - Next.js getStaticPaths 与 json 数组
- sql - 执行查询字符串并获得具有不同列数的结果
- apache-spark - Iceberg GCS 和一致性
- php - Php Mysql 列值不在逗号分隔的字符串中
- vue.js - 图像未在 vue js 中加载
- python - 使用递归在字符串中添加字符和空格
- opencv3.0 - 是否可以使用 cv2.Videocapture 在 Ubuntu 18.04 上访问大于 7 索引的视频设备?
- javascript - 如何按日期属性仅对对象数组中的少数元素进行排序