There are three errors in that code:
use requires the fully qualified name of a class, not its namespace.
Drupal doesn't have any
Drupal\Core\Datetime class. There is the
Drupal\Core\Datetime\DrupalDateTime class, which is the class you want to use.
The second argument of the constructor of
DrupalDateTime isn't necessary since, as the documentation for
DrupalDateTime::__construct() says, it's not used when the string passed as first argument specifies a timezone.
$timezone: PHP DateTimeZone object, string or
NULL allowed. Defaults to
NULL. Note that the
$timezone parameter and the current timezone are ignored when the
$time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00). @see http://php.net/manual/datetime.construct.php
The code you should use is then the following one.
$myDateTime = new DrupalDateTime($item['start_date']);
The code you are using doesn't return any value because you are using a class that doesn't exist. It should raise an error, as the code is referring a class that PHP cannot find.
As side note, the
DrupalDateTime class should be used when a class, a method, or a function requires an instance of that class, you need a class that is more flexible than the
DateTime class, or you need one of the methods that Drupal extends, for example
In the other cases, you should use the
DateTime class implemented in PHP.
See also the documentation for
DateTimePlus, which makes the difference between the PHP class and the Drupal classes clearer.
This class wraps the PHP
DateTime class with more flexible initialization parameters, allowing a date to be created from an existing date object, a timestamp, a string with an unknown format, a string with a known format, or an array of date parts. It also adds an errors array and a
__toString() method to the date object.
This class is less lenient than the
DateTime class. It changes the default behavior for handling date values like '2011-00-00'. The
DateTime class would convert that value to '2010-11-30' and report a warning but not an error. This extension treats that as an error.
As with the
DateTime class, a date object may be created even if it has errors. It has an errors array attached to it that explains what the errors are. This is less disruptive than allowing datetime exceptions to abort processing. The calling script can decide what to do about errors using