在yii2中的两个日期之间搜索 [英] search between two dates in yii2

查看:19
本文介绍了在yii2中的两个日期之间搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

日期可以用不同的格式表示.表格本身看起来像这样:

 book varchar(250) NOT NULL,日期 INT 非空

现在我的问题是我无法在两个日期之间的范围内实现搜索.例如,有5本日期不同的书,但开始日期从在 31/12/14 和最终日期是 31/02/15.因此,当用户选择这些日期之间的范围时,它必须提供该日期范围内的所有图书.

有没有办法在Yii2中做到这一点?到目前为止我找不到任何东西

更新

我正在实现一个不属于 GridView 的自定义过滤器,它看起来像是表格外的一个独立框.

看起来像这样:

日期范围:<输入名称=开始"/><输入名称=结束"/>书名:<input name="book"/>

解决方案

我相信这是您需要的答案:

$model = ModelName::find()-> where([' between', 'date', "2014-12-31", "2015-02-31" ])->all();

A date can be represented in different formats. A table itself looks like so:

   book varchar(250) NOT NULL,  
   date INT NOT NULL

Now my problem is that I can not implement search in range between two dates. For example, there are 5 books with different dates, but the start date starts at 31/12/14 and final date is 31/02/15. So when a user selects a range between these dates, it must provide all books in that date range.

Is there any way to do it in Yii2? I could not find anything so far

UPDATE

I'm implementing a custom filter which doesn't belong to GridView and it looks like as a standalone box outside the table.

It looks like so:

<div class="custom-filter">

   Date range:
     <input name="start" />
     <input name="end" />

   Book name:
     <input name="book" />

</div>

解决方案

I believe this is the answer you need:

$model = ModelName::find()
->where(['between', 'date', "2014-12-31", "2015-02-31" ])->all();

这篇关于在yii2中的两个日期之间搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆