2016-12-16 93 views
-1

我有當前日期時間,交貨日期時間如何獲得兩個日期之間的一半DateTime?

$del_time = $this->input->post('bid_time');  
date_default_timezone_set('Asia/Kolkata'); 
     $now = date('Y-m-d H:i:s'); 

我想日期時間的確切一半在當前日期時間,交貨日期時間之間的YMD H:我:秒鐘時間在PHP

+0

你是什麼意思的一半時間?你想舉兩個例子嗎? –

+2

你有沒有試過目前爲止的任何事情?如*計算差異,除以2並將其添加到一個日期*? –

+1

你有幾個關於它的例子:http://stackoverflow.com/questions/24798213/how-can-i-calculate-the-mid-point-between-two-dates-in-php和這裏:http: //sackoverflow.com/questions/30967857/calculating-midpoint-of-two-times我希望它對你有幫助作爲一個有效的起點。 –

回答

1

您可以使用下面的代碼

date_default_timezone_set('Asia/Kolkata'); 
$del_time   = $this->input->post('bid_time'); //for ex '2016-12-01 12:30:00'; 
$now    = date('Y-m-d H:i:s'); 
$loc_del_date_time = strtotime($del_time); 
$loc_curr_date_time = strtotime($now); 
$loc_mid_time  = ($loc_del_date_time + $loc_curr_date_time)/2; 
$loc_mid_time  = round($loc_mid_time); 
echo $loc_new_date = date('Y-m-d H:i:s', $loc_mid_time); 

謝謝

+0

謝謝,它的工作原理。 –

相關問題