[英]php code calculate 30 minutes from created datetime field in table
在我的表格中,有一個創建的datetime字段 ,其中像2016-05-25 11:50:35這樣插入數據。
假設我的插入時間是11:50,當前時間是12:10,所以相差20分鍾。 現在,我需要檢查的是在一個變量中獲得此差異,並檢查差異> 30,那么編輯鏈接將不可見,否則可見。
下面是我的代碼。
我從數據庫中創建的datetime字段中提取了分鍾。
$var1 = $post['ShipperRating']['created'];
$time1 = date('i', strtotime($var1));
$finaltime = $time1;
echo $finaltime;
$createdDateTime = new DateTime($post['ShipperRating']['created']);
$createdDateTime->modify('+30 minutes');
if ($createdDateTime >= new DateTime()) {
echo '<a href="/url">Edit</a>';
}
使用strtotime( http://php.net/manual/en/function.strtotime.php )可以工作...
$var1 = $post['ShipperRating']['created'];
$time1 = strtotime($var1);
$finaltime = strtotime('+ 30 minutes',$time1);
echo date('Y-m-d H:i:s',$finaltime);
如果可以在代碼中嵌入Java腳本,請使用:
setTimeout(function() {
$("#your-link-id").remove();
}, 1000*60*30);
如果您想延遲php,請通過以下鏈接:
如果要使用PHP進行操作,則必須在30分鍾后刷新頁面,然后從服務器計算出已在其他答案中顯示的時間。 您可以使用標題功能設置刷新頁面的時間
header("Refresh: 300;url='http://example.com/example'");
使用以下功能(1800000毫秒= 30分鍾)
window.setTimeout('removelink()',1800000); //
function removelink()
{
//write Code to Remove your Link
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.