# BetweenColumnsCondition

> Class BetweenColumnCondition represents a BETWEEN condition where values is between two columns.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [conditions](/docs/api/yii/db/conditions/index.md) › BetweenColumnsCondition

| class | `yii\db\conditions\BetweenColumnsCondition` |
| --- | --- |
| Implements | [`ConditionInterface`](/docs/api/yii/db/conditions/conditioninterface/index.md) |
| Since | 2.0.14 |
| Source | [`framework/db/conditions/BetweenColumnsCondition.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/conditions/BetweenColumnsCondition.php#L43) |

Class BetweenColumnCondition represents a `BETWEEN` condition where
values is between two columns. For example:

```
new BetweenColumnsCondition(42, 'BETWEEN', 'min_value', 'max_value')
// Will be build to:
// 42 BETWEEN min_value AND max_value
```

And a more complex example:

```
new BetweenColumnsCondition(
   new Expression('NOW()'),
   'NOT BETWEEN',
   (new Query)->select('time')->from('log')->orderBy('id ASC')->limit(1),
   'update_time'
);

// Will be built to:
// NOW() NOT BETWEEN (SELECT time FROM log ORDER BY id ASC LIMIT 1) AND update_time
```

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a condition with the `BETWEEN` operator. | `BetweenColumnsCondition` |
| [`fromArrayDefinition()`](#method-fromArrayDefinition) static | Creates object by array-definition as described in [Query Builder – Operator format](/docs/guide/db-query-builder/index.md#operator-format) guide article. | `BetweenColumnsCondition` |
| [`getIntervalEndColumn()`](#method-getIntervalEndColumn) |  | `BetweenColumnsCondition` |
| [`getIntervalStartColumn()`](#method-getIntervalStartColumn) |  | `BetweenColumnsCondition` |
| [`getOperator()`](#method-getOperator) |  | `BetweenColumnsCondition` |
| [`getValue()`](#method-getValue) |  | `BetweenColumnsCondition` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(mixed $value, string $operator, string|yii\db\ExpressionInterface $intervalStartColumn, string|yii\db\ExpressionInterface $intervalEndColumn)
```

Creates a condition with the `BETWEEN` operator.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$value` | `mixed` | The value to compare against |
| `$operator` | `string` | The operator to use (e.g. `BETWEEN` or `NOT BETWEEN`) |
| `$intervalStartColumn` | `string\|`[`yii\db\ExpressionInterface`](/docs/api/yii/db/expressioninterface/index.md) | The column name or expression that is a beginning of the interval |
| `$intervalEndColumn` | `string\|`[`yii\db\ExpressionInterface`](/docs/api/yii/db/expressioninterface/index.md) | The column name or expression that is an end of the interval |

### fromArrayDefinition() <span id="method-fromArrayDefinition"></span>

```php
public static function fromArrayDefinition(mixed $operator, mixed $operands): static
```

Creates object by array-definition as described in
[Query Builder – Operator format](/docs/guide/db-query-builder/index.md#operator-format) guide article.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$operator` | `mixed` | Operator in uppercase. |
| `$operands` | `mixed` | Array of corresponding operands |

**Returns**

`static`

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if wrong number of operands have been given.

### getIntervalEndColumn() <span id="method-getIntervalEndColumn"></span>

```php
public function getIntervalEndColumn(): string|yii\db\ExpressionInterface|yii\db\Query
```

**Returns**

`string|`[`yii\db\ExpressionInterface`](/docs/api/yii/db/expressioninterface/index.md)`|`[`yii\db\Query`](/docs/api/yii/db/query/index.md)

### getIntervalStartColumn() <span id="method-getIntervalStartColumn"></span>

```php
public function getIntervalStartColumn(): string|yii\db\ExpressionInterface|yii\db\Query
```

**Returns**

`string|`[`yii\db\ExpressionInterface`](/docs/api/yii/db/expressioninterface/index.md)`|`[`yii\db\Query`](/docs/api/yii/db/query/index.md)

### getOperator() <span id="method-getOperator"></span>

```php
public function getOperator(): string
```

**Returns**

`string`

### getValue() <span id="method-getValue"></span>

```php
public function getValue(): mixed
```

**Returns**

`mixed`