【问题标题】:Get the dates from a database table that are out side an array of dates从日期数组之外的数据库表中获取日期
【发布时间】:2021-10-16 15:12:51
【问题描述】:

我有一个日期数组,例如:

array:5 [
  0 => "2021-12-06"
  1 => "2021-12-07"
  2 => "2021-12-08"
  3 => "2021-12-09"
  4 => "2021-12-10"
]

我有一个数据库表,其结构如下:

id clinic_id start_date end_date

start_dateend_date 是日期时间字段。

如何使用laravel eloquent从该表中获取不在数组中的所有数据?

【问题讨论】:

  • 你的问题有点不清楚。您正在搜索在列表中的日期之外有句点(开始-结束)的所有 tupil?

标签: php laravel eloquent


【解决方案1】:

您的日期是字符串还是 Carbon 实例?您可以使用 LIKE 查询匹配字符串,因为我们不检查时间。

如果是Carbon 实例,请先使用$str = $date->format('Y-m-d');

$query = Clinics::query();

foreach ($dates as $date) {
    $query->where('start_date', 'not LIKE', $date.'%')
          ->where('end_date', 'not LIKE', $date.'%');
}

【讨论】:

    猜你喜欢
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多