2014-09-11 2 views

답변

3

그 의미가 있도록 두 배 사이에 제로 시간 차이가 다음과 같이

<?php 
include_once 'db_connect.php'; 
include_once 'psl-config.php'; 
include_once 'functions.php'; 

$error_msg = ""; 

sec_session_start(); 

//Get Username from session id 
$username = htmlentities($_SESSION['username']); 

//get time date stamp 
date_default_timezone_set('America/Chicago'); //set default timezone, just to be sure 


//GET Last Clockin from timesheet table 
$result = $mysqli->query("SELECT lastclockin FROM timesheet WHERE username = '$username'"); 
$number_of_rows = $result->num_rows; 

while ($row = mysqli_fetch_assoc($result)) { 
     $lastclockin = $row["lastclockin"]; 
    } 
    echo $lastclockin; 
    echo "<br />"; 

    $now = new DateTime(); 

    $diff = $now->diff(new DateTime($lastclockin)); 

$hours = $diff->h; 
$minutes = $diff->m; 
$hours = $hours + ($diff->days*24); 

echo $now->format('Y-m-d H:i:s'); 
echo "<br />"; 

echo $hours; 
echo "<br />"; 
echo $minutes; 
echo "<br />"; 
?> 

결과이다. 여기서 0보다 큰 값을 보려면 두 번 더 멀리 떨어져있는 것을 테스트해야합니다.

m이 월 식별자이므로 분이 잘못되었습니다. i은 몇 분 동안입니다.

$minutes = $diff->i; 
+0

멍청한 짓 ... – user3690146

관련 문제