2012-10-28 39 views
-1

我需要檢索從當前日期時間+某段時間開始的過期日期時間。PHP-如何檢索到期日期時間

的例子是:

$current_datetime = date('Y-m-d H:m:s'); 
$expire_time = 24;// 1 day in hours as int() for example ;) 

$expire_datetime = date($current_datetime + $expire_time); //don't know how to do this in Y-m-d H:m:s format!! 

我想寫下的幫手LIB從這個腳本啓動。

+0

http://php.net/manual/en/datetime.add.php http://stackoverflow.com/questions/ 985818/php-date-time-current-time-add-minutes http://stackoverflow.com/questions/2242601/add-days-and-hours-in-date-time-field-and-get-the-updated -date-time-in-php-using http://stackoverflow.com/questions/7811609/php-add-two-hours-to-date-variable – Bugs

+0

或['strtotime'](http:// www .php.net/manual/en/function.strtotime.php) – air4x

回答

2

使用此

$expire_datetime = date('Y-m-d H:m:s',strtotime("NEXT DAY")); 

$expire_datetime = date('Y-m-d H:m:s',strtotime("tomorrow")); 
+0

哇,我怎麼能延長到1周或1個月或1年例如? – sbaaaang

+1

根據需要改變strtotime(「next week」) – StaticVariable

+0

@Ispuk或者你可以使用strtotime(「+ 1 week」) – StaticVariable

1
$date = date('Y-m-d H:m:s'); 
$newdate = strtotime ('+1 day' , strtotime ($date)) ; 
$newdate = date('y-m-d',$newdate) 
echo $newdate; 
+0

http://php.net/manual/en/function.strtotime.php - 「不建議使用此函數進行數學運算,最好使用DateTime :: add( )和PHP 5.3及更高版本中的DateTime :: sub(),或者PHP 5.2中的DateTime :: modify()。 – Bugs

+0

我可以將此延長至1周或1個月或1年嗎? – sbaaaang

+0

他問一個最小的讓他檢查這個手冊。他沒有提到php版本 –