-1

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)

1

2 Answers 2

3

Try This

echo date("Y", strtotime($string1));
echo date("Y", strtotime($string2));
echo date("Y", strtotime($string3));
Sign up to request clarification or add additional context in comments.

Comments

2

Easiest solution if the format is allways like you described:

echo substr($string1, 7,4);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.