2010-05-24 104 views
0

由于我的服务器没有升级到php 5.3(它在PHP 5.2.11版本中),date_sub不起作用。date_sub无法正常工作

这里是代码:$date = date_create(date('Y-m-d')); date_sub($date, date_interval_create_from_date_string('60 days')); $date1= date_format($date, 'Y-m-d');

但它在我的本地主机(即5.3),好吧,但不是在服务器(5.2.11)。

你能告诉我如何使这个日期扣除工作在5.2.11?

回答

5

the docs说,使用DateTime::modify()

3

$ date1 = date('Y-m-d',strtotime(“ - 60 days”));

工程:)

+0

的strtotime是在32位平台上的Y2K38问题的影响。新的DateTime类不是。 – 2010-05-24 07:07:27

0

随着manual page说,此功能仅适用于PHP版本> = 5.3.0。
所以,你已经找到正确的解决方案自己

0

为EX $ DA = 2014年4月1日

如果u想减去使用6个月的..

$date = strtotime($da .' -6 months'); 
$final=date('Y-m-d', $date); 

回声$决赛;

0

添加和subracting天

$newdate = date('Y-m-d', strtotime("-10 days")); 
echo $newdate; 

附件10天

$newdate1 = date('Y-m-d', strtotime("+10 days")); 
echo $newdate1; 

加10天

添加和subracting月

$newmonth = date('Y-m-d', strtotime("-5 months")); 
echo $newmonth; 

附件10月

$newmonth1 = date('Y-m-d', strtotime("+5 months")); 
echo $newmonth1; 

添加10个月