To use "LIKE" operator in Yii2 query builder, use the below code,
$sql = "SELECT * FROM TABLE_NAME WHERE item_code = :item_code AND DATE_FORMAT(req_date, '%Y-%m') LIKE :period";
$req_date = '%' . $req_date . '%';
$command = Yii::$app->db->createCommand($sql);
$command->bindParam('item_code', $item_code);
$command->bindParam('period', $req_date);
$result = $command->execute();
No comments:
Post a Comment