2014-10-09 50 views
0

我知道有很多這樣的問題,但我不能讓它們適用於我的情況,我在處理時差方面遇到問題。使用代碼點火器和我如果自提交一小時後更新記錄

蔭有中有「工作」與各個領域,其中之一是submitted_time (of type TIME)被設置爲date('H:i:s', time())在插入時和其他service_response(of type TIME)set manually to "02:00:00"在插入行的分貝。

我想寫一個函數,當運行時檢查是否已經過去了一小時後,但是無法理解完成此操作的最佳方式。

以下是我嘗試將所有字符串從兩個字段轉換爲unix時間戳並在提交時間大於現在時間+ 1小時(service_response/2)時回顯「作業」

function updateJobTimes() 
{ 
    $this->load->model('job_model'); 

    $oj = $this->job_model->getAllTodaysOpenJobs(); 
    //var_dump($oj); 
    foreach($oj as $job) 
    { 
     $timesubmitted = strtotime($job->submitted_time); 
     $now = strtotime(date('H:i:s', time())); 
     //responsetime = now + 1 hour; 
     $responsetime = strtotime("+1 hours"); 

     echo "Submitted_time =" . $job->submitted_time. "<br>\r\n"; 
     echo "strtotime(Submitted_time) =". $timesubmitted. "<br>\r\n"; 
     echo "Service_reponse =" . $job->service_response. "<br>\r\n"; 
     echo "strtotime(Serivce_response) =" .$responsetime. "<br>\r\n"; 
     echo "Time now =".$now. "<br>"; 
     echo "response time(now +1hour) =". date('H:i:s', $responsetime) ."<br>"; 
     echo "-----just a separator---------------------------------- <br>"; 




     //this should show the last job "job#2105" which is the last iteration in the picture below 
     if($timesubmitted > $responsetime) 
     { 
      $difference = $res - $timesubmitted; 
      echo "<p class='well'>Job #".$job->reference. "</p>\r\n"; 
     } 
    } 
} 

但它永遠不會或總是滿足條件。

我真的很茫然,已經閱讀了谷歌出現的每一個問題,但他們要麼基於時間和日期是在同一個領域或想返回一個用戶可讀的字符串,如「x分鐘前」或他們使用sql select語句,但我已經有了一個聲明,只從當前日期(上)撤回作業,我只是想列出這些作業,如果他們已被提交超過一個小時。

很抱歉,如果問題太長,太愚蠢或者沒有提供足夠的信息(或者太多),我會問,因爲我迷路了。

編輯:更新方法A與@ChrisG的幫助,並添加了圖片顯示的問題(即最後一份工作(#2105)不應該在那裏)

編輯2:再次更新方法更新圖片以顯示正在檢查的變量。

**編輯3:我有一種感覺看我的代碼,條件將永遠不會被滿足,因爲提交的時間永遠不會比現在的任何時間更大+1小時,因爲現在總是會改變...我覺得這很愚蠢,只是寫出來,但我似乎沒有把它說得正確,如果說得對,我現在比以前更接近但仍然失敗。也許響應時間應該是提交時間+一小時? **

感謝您閱讀

變量

enter image description here

+0

您是否試過將strtotime()生成的所有時間戳轉儲並比較? – ChrisG 2014-10-09 20:31:22

+0

嗨,感謝您的閱讀,是的,我會更新顯示他們的圖片,我沒有收錄他們,因爲我認爲我錯誤地使用了這個功能,所以他們本來是不相關的。 – Pheonix2105 2014-10-09 20:33:15

+0

對不起,忘了補充一下,我把它們甩了,但是因爲它們數量太大,我不能(看:我笨)真的自己驗證了它們。 – Pheonix2105 2014-10-09 20:34:07

回答

0

我計算出來的VAR轉儲。

function updateJobTimes() 
{ 
    $this->load->model('job_model'); 

    $oj = $this->job_model->getAllTodaysOpenJobs(); 
    //var_dump($oj); 
    foreach($oj as $job) 
    { 
     $timesubmitted = strtotime($job->submitted_time); 
     $now = strtotime(date('H:i:s', time())); 

     $responsetime = strtotime("+1 hours", $timesubmitted); 

     // echo "Submitted_time =" . $job->submitted_time. "<br>\r\n"; 
     // echo "strtotime(Submitted_time) =". $timesubmitted. "<br>\r\n"; 
     // echo "strtotime(Serivce_response) =" .$responsetime. "<br>\r\n"; 
     // echo "Time now =".$now. "<br>"; 
     // echo "response time(now +1hour) =". date('H:i:s', $responsetime) ."<br>"; 
     // echo "-----just a separator---------------------------------- <br>"; 





     if($now > $responsetime) 
     { 
      //$difference = $res - $timesubmitted; 
      echo "<p class='well'>Job #".$job->reference. " was submitted at ".date('H:i:s',$timesubmitted). " and its response time is " .date('H:i:s',$responsetime). " and it is now ".date('H:i:s',time()). "</p>\r\n"; 
     } 
    } 
} 

基本上我在做if(the time submitted was greater than the time submitted + 1hour)這將永遠是真實的我應該做的事情是什麼if(**thetimenow** is greater than time_submitted + 1 hour) //這在我的情況下,應返回所有的結果,除了1,這是這樣,希望它可以幫助任何人一樣困惑我曾是。

不能確定接受你自己的答案作爲解決方案,因此我不會的禮儀,但這樣做的工作,我坦白地說可能已經是有道理的大多數人,我剛剛在這個問題追了上來。

相關問題