2012-10-23 168 views
0

我目前正在处理包裹订阅管理器,在此我必须通过在当前日期中添加持续时间来计算到期日期。在当前日期时间中添加日期时发生的天数

下面是我的代码,做它:

function generateExpiryDate($start_date, $package_duration) 
{ 
    $expires = strtotime(date($start_date)." + $package_duration"); 
    return date("Y-m-d H:i:s", $expires); 
} 

$current_date = "2012-10-23 19:12:19"; 
$duration = "6 Months"; 
$expiry_date = generateExpiryDate($current_date, $duration); 

当我回声$ CURRENT_DATE和$ EXPIRY_DATE,它显示 2012年10月23日19时41分14秒 2013年4月23日19:41 :14

注意,它只是增加月中的月份,并且不会照顾31天,28天,29天或30天等月份中的任何一天。 我希望它考虑到这些事情。

请帮我解决问题。

+1

10.23.2012 + 6个月*是* 4.23.2013 - 你想要的是什么? – jedwards

+1

$ date = strtotime(date(“Y-m-d”,strtotime($ date))。“+6 month”);类似于这个 – Ghostman

+0

是的,我意识到,在我彻底地完成了测试之后,它的工作正常。 – Asnexplore

回答

0
$date = date($current_date);// current date 
$expiry_date =strtotime(date("Y-m-d", strtotime($date)) . " +6 month");