简体   繁体   English

我有两个字段分别称为created_at和Updated_at(timestamps),我想在where子句中的这些日期之间进行搜索

[英]i have two fields named as created_at and updated_at(timestamps) and i want to search between these dates in my where clause

i want to take input date as a parameter and search between the dates that are given in input. 我想将输入日期作为参数,并在输入中给定的日期之间进行搜索。

Theses are the timestamps() provided by laravel to create the two fields as created_at and upated_at.I want to search between these dates that are given in created_at and updated_at but unable to find the data between these dates. 这些是laravel提供的创建stamped_at和upated_at这两个字段的时间戳()。我想在created_at和updated_at中给出的这些日期之间进行搜索,但是无法找到这些日期之间的数据。 Following is the code that i have create 以下是我创建的代码

` $startDate = $request->input('created_at');
  $endDate   = $request->input('updated_at');

->select()
->whereBetween('created_at','updated_at',[$startDate,$endDate])
->get();`

I think whereBetween only accepts 2 parameters. 我认为whereBetween仅接受2个参数。 The first being the column name and the second the array with values to test. 第一个是列名,第二个是要测试值的数组。 Check: https://laravel.com/docs/5.5/queries#where-clauses 检查: https : //laravel.com/docs/5.5/queries#where-clauses

You would want something like: 您会想要类似:

->whereBetween('created_at', [$startDate,$endDate])
->whereBetween('updated_at', [$startDate,$endDate])

The error: 错误:

Argument 2 passed to Illuminate\\Database\\Query\\Builder::whereBetween() must be of the type array 传递给Illuminate \\ Database \\ Query \\ Builder :: whereBetween()的参数2必须为数组类型

is because the second parameter of whereBetween() is an array, and you pass a string 'updated_at' here. 这是因为whereBetween()的第二个参数是一个数组,并且您在此处传递了字符串'updated_at' So change it to like: 因此,将其更改为:

->whereBetween('created_at', [$startDate,$endDate])
->whereBetween('updated_at', [$startDate,$endDate])

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails时间戳:由updated_at / created_at组成的复杂顺序 - Rails timestamps: complex order by updated_at / created_at 如何更新 Laravel Eloquent 管理的时间戳(created_at 和 updated_at)的时区? - How to update the timezone for the timestamps (created_at and updated_at) managed by Laravel Eloquent? 按`updated_at`和`created_at`排序,即使它们为NULL - Order by `updated_at` and `created_at` even if they are NULL Laravel:created_at 和 updated_at 是未来 2 小时 - Laravel: created_at and updated_at is 2 hours in the future 在Laravel 4中更改created_at和Updated_at的格式 - Changing the format of created_at and updated_at in Laravel 4 如何获取最新的 created_at 和 updated_at - How to get lastest created_at and updated_at 在Laravel中用2个小时检索update_at早于created_at的记录(雄辩) - Retrive records where updated_at is older than created_at with 2 hours in Laravel (eloquent) 字段 'fullname' 没有默认值(SQL:插入到 `contacts` (`updated_at`, `created_at`) - Field 'fullname' doesn't have a default value (SQL: insert into `contacts` (`updated_at`, `created_at`) Laravel 5.1更新消息,但同时涉及created_at和Updated_at - Laravel 5.1 Update message but it touch both created_at and updated_at 按created_at和updated_at的顺序选择两次记录 - Selecting a Record twice in order of created_at and updated_at
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM