Still yesl how to filter. Here is the code

I need to filter out all who are 18 years of age.

Function starts to swear on the parameters $date1, $date2. Tell me how to do it?

```
$query=Direction::find()->joinWith(['pacients' => function ($q) {
$q->where('pacients.dr="1990-02-25"');
}]);
```

I need to filter out all who are 18 years of age.

```
$yearOfBirth = 18;
$date1 = date((date('Y') - $yearOfBirth - 1) . '-m-d');
$date2 = date((date('Y') - $yearOfBirth) . '-m-d');
$query=Direction::find()->joinWith(['pacients' => function ($q, $date1, $date2) {
$q->where("pacients.dr BETWEEN $date1 AND $date2");
}]);
```

Function starts to swear on the parameters $date1, $date2. Tell me how to do it?

asked June 8th 19 at 17:30

1 answer

answered on

Solution

```
$yearOfBirth = 18;
$date1 = date((date('Y') - $yearOfBirth - 1) . '-m-d');
$date2 = date((date('Y') - $yearOfBirth) . '-m-d');
$query=Direction::find()->joinWith(['pacients' => function ($q) use ( $date1, $date2) {
$q->where("pacients.dr BETWEEN :d1 AND :d2",["d1"=>$date1,"d2"=>$date2]);
}]);
```

Thank you!!!:) - Kade70 commented on June 8th 19 at 17:35

Find more questions by tags Yii