mysql - YII2 get the date after 10 years and 5 years -


here table structure.

tbl_staff

firstname varchar(50) midname varchar(50) lastname varchar(50) ... 

tbl_staff2

first_day_of_service date ... 

here scenario. first 10 years of stay of staff in organization, he/she given loyalty award , every 5 years after he/she receives first 10 years.

my initial code name of staff , date of first day of service.

public function actionget_loyalty() {          $query = (new \yii\db\query())                 ->select(['firstname', 'midname', 'lastname', 'first_day_service'])                 ->from('tbl_staff')                 ->limit(100)                 ->offset(0)                 ->orderby('first_day_service')                 ->leftjoin('tbl_staff2', 'tbl_staff2.staff_id = tbl_staff.id');         $command = $query->createcommand();         $data = $command->queryall();         $string = "<table class='table table-striped'><tr><th>no.</th><th>name</th><th>date receive loyalty award</th></tr>";         $i = 1;         foreach ($data $row) {             $firstname = $row['firstname'];             $midname = $row['midname'];             $lastname = $row['lastname'];             //$string.=$row['first_day_service'];             $string.="<tr>"                     . "<td>$i</td>"                     . "<td>" . $firstname . " " . $midname[0] . ". " . $lastname . "</td>"                     . "<td>" . $row['first_day_service'] . "</td>"                     . "</tr>";             $i++;         }         $string.="</table>";         return $string;     } 

how display name of staff , date he/she receive award in increasing order.

or mysql query sort name according date?

if want via sql query, in mysql can add date using date_add function:

date_add(date, interval 5 year) 

check this similar question.

or via php using datetime modify method:

$datetime = new datetime($date); $datetime->modify('+ 5 years')->format('y-m-d h:i:s'); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -