我为我正在处理的应用编写了以下代码:
$tmp = $this->getConfig()['brandIds'];
$unexpired_brands = array();
$expired_brands = array();
foreach($tmp as $key => $value)
{
$brand = $this->getBrandModel()->getBrandById($value);
$currentDate = new \DateTime(date("Y-m-d"));
$startDate = new \DateTime($brand["startDate"]);
$expireDate = date_add($startDate, date_interval_create_from_date_string('7 days'));
// this date right here gets modified and on its original value 7 days are added
if($currentDate>$expireDate)
// Checking if current date is bigger than expire date.(Ex. 20.5.2016 > (startDate)+7 days) ? Yes
// Assumption is that start date is < currentDate
{
date_add($brand["startDate"],date_interval_create_from_date_string("7 days"));
// However?? This one isn't ?? It stays the same as the one that is fetched from
// the db, which is $brand["startDate"] == currently set on 2016-05-10
array_push($expired_brands,$brand);
}
else
{
date_add($brand["startDate"],date_interval_create_from_date_string("7 days"));
// neither this one is modified ??? How can I modify these date as the one I've shown above??
array_push($unexpired_brands,$brand);
}
}
正如您在上面所看到的,我无法修改我从数据库中提取的日期值,并且我能够修改我已创建的本地变量检查currentdate
是否大于到期日期......
有人可以帮我解决这个问题吗?谢谢堆!!!“
答案 0 :(得分:0)
$brand["startDate"]
是约会对象吗?发表var_dump($brand["startDate"])
声明;它应该告诉你变量类型。
答案 1 :(得分:0)
我明白了
date_add($startDate, date_interval_create_from_date_string('7 days'));
工作但是
date_add($brand["startDate"],date_interval_create_from_date_string("7 days"));
没有工作。
也许它是引用问题的双引号而你没有添加
new \DateTime($brand["startDate"])
更改那些无法使用
的内容date_add(new \DateTime($brand["startDate"]),date_interval_create_from_date_string('7 days'));
因为你似乎想要做同样的事情。