I have a couple of strings which look like this:
$string1 = '03 Aug 2020 00:49'
$string2 = '15 Sep 2019 23:02'
$string3 = '21 Jul 2018 22:48'
How can i grab the year only out of the string? ( so 2020
or 2019
or 2018
)
Advertisement
Answer
Try This
echo date("Y", strtotime($string1)); echo date("Y", strtotime($string2)); echo date("Y", strtotime($string3));