Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class TestController extends Controller
- {
- public function actionIndex()
- {
- $time1 = '11:30';
- $time2 = '12:00';
- list($hours, $minutes) = explode(':', $time1);
- $startTimestamp = mktime($hours, $minutes);
- list($hours, $minutes) = explode(':', $time2);
- $endTimestamp = mktime($hours, $minutes);
- $seconds = $endTimestamp - $startTimestamp;
- $minutes = ($seconds / 60) % 60;
- $hours = round($seconds / (60 * 60));
- echo "Time passed: <b>$hours</b> hours and <b>$minutes</b> minutes";
- }
- public function actionReal()
- {
- if(isset($_POST['Apaaja']))
- {
- //Collect semua data dari form
- $model->attributes = $_POST['Apaaja'];
- //Ambil data waktu_awal dan waktu_akhir
- $time1 = $model->waktu_awal;
- $time2 = $model->waktu_akhir;
- //Prosesnya disini . . . . . .
- list($hours, $minutes) = explode(':', $time1);
- $startTimestamp = mktime($hours, $minutes);
- list($hours, $minutes) = explode(':', $time2);
- $endTimestamp = mktime($hours, $minutes);
- $seconds = $endTimestamp - $startTimestamp;
- $minutes = ($seconds / 60) % 60;
- $hours = round($seconds / (60 * 60));
- //Siapin data hasil proses yg akan masuk ke database
- $model->selisi_jam = $hours;
- $model->selisi_menit = $minutes;
- if($model->save()){
- $this->redirect('index');
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement