public static function GetRate($id, $time = null) { if ($time == null) { $time = Record::writeDate(time()); } $date = Currates::find()->andWhere(['currency_id' => $id])->andFilterWhere(['>=', 'date', $time])->orderBy(['date' => SORT_ASC])->One(); if ($date == null) { //no value then get latest $date = Currates::find()->andWhere(['currency_id' => $id])->orderBy(['date' => SORT_DESC])->One(); } if ($date == null) { //no rate return 1; } return $date->value; }