A more OOP way than @TobSpr would be using DateTime
$date = "2013-01-29";
$dt = new DateTime($date);
echo $dt->format('Y');
This have the advantage that we have full control over the date, we can even specify a specific timezone, handle poorly formatted input date strings (DateTime __construct will throw an exception on unparsable input)
$date = "2013-01-29 invalid";
try {
$dt = new DateTime($date);
echo $dt->format('Y');
} catch (Exception $e) {
printf('Failed to decode input date "%s", PHP said: %s', $date, $e->getMessage());
}
For information on what you can send into DateTime::format
, see date