2014-02-24 26 views
0

與訂閱成員的截止日期一樣。將30天添加到sql中的變量,然後在php中回顯

聽起來很簡單,但我得到的只是1969年1月31日!

例如。

<? $expire = strtotime("+30 days",$subscribed); echo $expire;?> 

SQL條目已經使用Y-M-D格式,並且在剛剛作爲變量回顯時工作正常。

但是,當我嘗試添加30天的$訂閱值我得到的是數字的一束穿過.date功能放時31-01-1969

也許一個簡單的解決方案,但出現我是一個noob哈哈。

感謝所有幫助:)

+0

你有一些錯誤,所以只顯示31-01-1969 –

+1

目前,$ subscribed變量中包含什麼? – elimirks

回答

0

試試這個:

$expire = date('Y-m-d', strtotime($subscribed. ' + 30 days')); 
echo $expire; 

閱讀更多關於strtotime

0

strtotime第二個參數應該是作爲相對日期的計算的基準時間戳

試試這個。

$expire = date('Y-m-d', strtotime("+30 days", strtotime($subscribed))); 
echo $expire; 
0

使用下面的代碼爲30天加上與您約會

<?php 
$expire = date('Y-m-d', strtotime($subscribed . " +30 days")); 
echo $expire; 
?> 
+0

太棒了。像魅力一樣工作。感謝幫助的人。我確定我會回來:) – jay32mcr

1

你必須告訴PHP,你的字符串是一個日期和使用日期時間對象:

<?php 
$date = new DateTime($subscribed); 
$date->add(new DateInterval('P30D')); 
$expire = $date->format('Y-m-d'); 
echo $expire; 
?> 
相關問題