mysql - Laravel 时间范围
问题描述
我正在使用 Laravel 5.8,我有两列数据类型为时间戳,start_time 和 end_time。在保存新记录之前,我想检查它是否已经存在。
例如,如果我的数据库中已经有Start Time= 09:00:00, End Time: 17:00:00我不应该设置 start time = 13:00:00 和 end_time=16:00:00 因为它已经在现有的时间间隔内,我也不应该注册16:00:00->20:00:00因为 16:00:00 在时间间隔内。
到目前为止,我有这个,它不起作用:
DB::table('student_classes')
->where('id', '!=', $id)
->whereNotBetween('start_date', [$data['start_date'], $data['end_date']]);
解决方案
@MahdiMiad 您如何在数据库中节省时间-它是时间戳还是字符串?我希望你使用时间戳。
在保存之前进行查询。
$rows = DB::table('student_classes')->whereNotBetween('start_date', [$data['start_date'],$data['end_date']])->get();
if (count($rows)>0) {
// throw error
} else {
// save the results
}
推荐阅读
- ubuntu - 无法使用 Ubuntu 20 中的终端连接到 Postgresql
- tensorflow2.0 - cocoEval summarise() 返回所有mAP -1
- mysql - MySQL 无法从子查询中的查询访问字段
- amazon-web-services - 我无法将 Docker 映像推送到 AWS ecr
- sql - 我们可以在 Google Cloud SQL 中创建多少个数据库?
- c - 素数和:结果有什么问题?
- blazor - ITfoxtec.Identity.BlazorWebAssembly.OpenidConnect blazor 示例无法检索元数据
- html - 在 django 中清除浏览器缓存
- sql-server - Alembic MSSQL 唯一约束允许空值
- wordpress-rest-api - 在 WordPress 中使用 WPML 和 REST API 创建第二语言的翻译帖子