Calculate the number of days since the creation date of a user account I would like to calculate the number of days past since a users creation date. This is what I have done so far:

$user = \Drupal::currentUser();
$registrationdate = getdate($user-&gt;getCreatedTime());
$today = getdate();
$daypast = date_diff($regdate, $today);


This results in the following error:


  date_diff() expects parameter 1 to be DateTimeInterface


How can I solve this and get the number of days past since the users registration date?
This depends on what you need to do with it.  If you truly just need the number of days, then this will work

$user = \Drupal::currentUser();
$created = new \DateTime('@' . $user-&gt;getAccount()-&gt;getCreatedTime());
$interval = $created-&gt;diff(new \DateTime());
$days1 = $interval-&gt;d
$days2 = intval($interval-&gt;format('%d'));


Here $days1 and $days2 should give you the same value.  See the docs for \DateTime and \DateInterval for more information.

If you need a nifty string for output purposes, then check out DateFormatter::formatTimeDiffSince() and friends:

$user = \Drupal::currentUser();
$created = $user-&gt;getAccount()-&gt;getCreatedTime();
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
$created_since = $date_formatter-&gt;formatTimeDiffSince($created);


and then $created_since will be a string like '7 weeks 2 days'.  You can also use the 'Time ago' formatter directly in the entity rendering configuration.  The default view for the accounts listing does this.