0

Im looking for the less complicated way to do the following:

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

Is there a function that can help me with this?

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Marilee
  • 1,598
  • 4
  • 22
  • 52

1 Answers1

-1

You should be using DateTime Object for these operations

$joinDate = "2014-05-26";

$joinDate_obj = new DateTime($joinDate);
$now = new DateTime();
$interval = $joinDate_obj->diff($now);

$diff = $interval->d ;

echo $diff; //12

The object $interval will have

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 

) So you may use for example $interval->days for the difference in days.

Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
  • And what will the result be, for example, if there is more than 50days difference? – Glavić May 08 '15 at 07:15
  • @Glavić $interval object will have all the data for difference so I would say just do a var_dump() and see what all you have and use them (for op), if you are specif to find the difference in days between 2 days use `$interval->days`, – Abhik Chakraborty May 08 '15 at 07:21