php减去当前日期的过去日期,并以天为单位获得结果

时间:2015-05-08 06:45:18

标签: php date datetime

我正在寻找不太复杂的方法来执行以下操作:

$joinDate = "2014-05-26"
$date = date('Ymd'); //todays date
$memberFor = $joinDate - $date //This is where I need to get total number of days

是否有可以帮助我的功能?

1 个答案:

答案 0 :(得分:-1)

您应该使用DateTime Object进行这些操作

//4

对象$joinDate = "2014-05-26"; $joinDate_obj = new DateTime($joinDate); $now = new DateTime(); $interval = $joinDate_obj->diff($now); $diff = $interval->d ; echo $diff; //12 将有

$interval

) 因此,您可以使用DateInterval Object ( [y] => 0 [m] => 11 [d] => 12 [h] => 12 [i] => 49 [s] => 4 [weekday] => 0 [weekday_behavior] => 0 [first_last_day_of] => 0 [invert] => 0 [days] => 347 [special_type] => 0 [special_amount] => 0 [have_weekday_relative] => 0 [have_special_relative] => 0 作为天数差异。